我正在使用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),當實體被填充時,它也填充導航屬性。 –