我正在使用EF6,并且试图获取实体列表。对于列表中的每个实体,我希望它在一次调用中填充子实体。如何获取实体及其所有相关实体
例如:
Order.Id
Order.ColletionOfItems
Item.Id
Item.OrderId
Item.ProductName
Item.CollectionOfOptions
Option.Name
Option.Value
using(var db = DbContext)
{ //I want to fill in everything during this call as I am using all of it in the
//The calling function.
OrderList = db.Orders.Select().include //This is where I am stuck
return OrderList;
}
我想返回的集合有所有的订单,关联到单个订单的所有项目,并关联到单个项目的所有选项。
如何构建linq语句来完成此操作?那么.Include("MyMajicString")
有没有更好的方法?我应该实际搜索什么,因为我的搜索导致很少可接受的回复?
我相信如果你有子实体的导航属性,你甚至不需要使用include()(除非你有ProxyCreationEnabled = false),当实体被填充时,它也填充导航属性。 –