I am having issue with the Include function. I have a Team class that has an Owner property of type Owner. I have a helper function that wraps my EF calls like below;
public Task<List<T>> GetManyAsync(
Expression<Func<T, bool>> filter = null,
Expression<Func<T, object>> includeProperties = null)
{
IQueryable<T> query = _dbSet;
if (filter != null)
{
query = query.Where(filter);
}
if (InstanceHelper.IsSomething(includeProperties))
{
query.Include(includeProperties);
}
return query.ToListAsync();
}
And I use it like this
var teams = await DataAccess.Team.GetManyAsync(e => e.Owner.Id == userId, e => e.Owner);
But it returns the list of Teams with a NULL Owner property. Any idea what I am missing here?
virtual
keyword specified before owners property declaration?null
in the database. Also, why not pass the expression? Why are you callingGetPropertyName()
first and what does it return?virtual
keyword is to allow lazy-load. Once you're eager-loading the property,virtual
is no longer required (although you'll lose change-tracking as well).