中的where或filter
下面的代码不能工作。Include路径表达式必须引用在类型上定义的导航属性。对引用导航属性使用点点路径,对集合导航属性使用Select操作符。我做错了什么
public static MyEntity GetData(this IQueryable<MyEntity> source, int id, int year)
{
return source.Where(x => x.ID == id)
.Include(x => x.Childrens1)
.Include(x => x.Childrens2.where(y => y.Year == year))
.FirstOrDefault();
}
在不支持Include表达式的地方,只能使用select,甚至嵌套。移出include
public static MyEntity GetData(this IQueryable<MyEntity> source, int id, int year)
{
return source
.Include(x => x.Childrens1)
.Include(x => x.Childrens2)
.Where(x => x.ID == id && x.Childrens2.Any(y => y.Year == year))
.FirstOrDefault();
}
现在,您还可以统一FirstOrDefault