所以我有类似这样的类。EF - 为什么不包含属性
public class User {
public virtual IList<Member> Members {get;set;}
}
public class Member {
public virtual AnotherTable Another {get;set;}
}
public class AnotherTable {
public string Name {get;set;}
}
当我直接对DataContext的执行查询包括的作品,但是当我对成员的IList做一个AsQueryable已()的包括不起作用。
有没有一种方法可以在延迟加载属性(例如上面的Members属性)上使用Include/Eager功能,还是我总是必须通过DataContext才能获得该功能?
User.Members.AsQueryable().Include(a => a.Another).ToList() // <-- nada, no way Jose
_db.Members.Include(m => m.Another).ToList() // <-- all good in the neighborhood
我问原因也可以是一个SQL语句对100个查询的东西,结果相当于一个巨大的差异。
在此先感谢。
这是一个很好的答案解决方案,刚刚结束了在我的datacontext上为常见查询场景创建专用属性。虽然也可以实施这个。 –