I have the following function in my generic repository which works fine:
public IQueryable<T> FindWhere(System.Linq.Expressions.Expression<Func<T, bool>> predicate, params string[] includes)
{
IQueryable<T> query = _dbSet;
foreach (var child in includes)
{
query = query.Include(child);
}
return query.Where(predicate);
}
I then also have this to find a single item:
public T FindById(int id)
{
return _dbSet.Find(id);
}
What I need is an override for FindById that will allow me to pass in params string[] includes to allow me to eager load properties on the individual item found.
How can I do this?
You can use the entity entry to load the related entities, however you need to know relationship multiplicity: