[英]Entity Framework Include() returns null navigational property
I am having issue with the Include function. 我遇到包含功能的问题。 I have a Team class that has an Owner property of type Owner. 我有一个Team类,其Owner属性为Owner。 I have a helper function that wraps my EF calls like below; 我有一个辅助函数,它包含我的EF调用,如下所示;
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. 但它返回具有NULL Owner属性的团队列表。 Any idea what I am missing here? 知道我在这里缺少什么吗?
You must use from this 你必须从中使用
public Task<List<T>> GetManyAsync(Expression<Func<T, bool>> filter = null, params Expression<Func<T, object>>[] includeProperties = null)
{
foreach (var prop in includeProperties)
query = query.Include(prop);
...
}
And you can have multiple includes 你可以拥有多个包含
GetManyAsync(filter ,p => p.prop1 ,p.prop2,...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.