可以说ParentObject包含包含GrandChildObjects的ChildObjects(所有这些都存储在数据库中),基本上是多个嵌套类,而且当我从dbContext检索ParentObject时我希望它完全填充/刷新,但是,ChildObjects通常为null,通过包含.Include(x => x.ChildObject)
来修复,但是如何对更深层次的嵌套对象执行此操作?到目前为止,我正在使用它来检索所有ParentObjects:
// db -> DbContext
return db.Parents
.Include(x => x.Child1)
.Include(x => x.Child2)
.Include(x => x.Child3);
// Now ChildObjects are refreshed, however objects inside them are not (GrandChildObjects)
答案 0 :(得分:1)
只需选择合适的属性即可。其中一个:
.Include(x => x.Child1.GrandChild)
或许多:
.Include(x => x.Child1.Select(c => c.GrandChild))