[英]Entity Framework Include and Select are gettind some other entities
我正在使用帶有Northwind數據庫的Entity Framework 6最新穩定版本。 我寫了一個查詢,如下所示。 甚至我也沒有包括要訂購的客戶。 並且還包括實體OrderDetails具有Order(這類似於遞歸)。 最終包含的OrderDetails實體產品甚至具有我未包含的類別。 奇怪的是,供應商是一個導航屬性,但對於產品則為null。
另外:LazyLoading和ProxyCreationEnabled為false
var orders = Context.Orders
.Include(i => i.Order_Details)
.Include(i => i.Order_Details.Select(a => a.Product))
.Where(i => i.EmployeeID == employeeId && i.CustomerID == customerId)
.ToList();
和OrderDetail的問題
我無法理解的是什么?
如果您不想從表中獲取不需要的數據,則可以進行選擇。您可以通過匿名選擇或使用視圖模型類來進行選擇
var orders = Context.Orders
.Include(i => i.Order_Details)
.Include(i => i.Order_Details.Select(a => a.Product))
.Where(i => i.EmployeeID == employeeId && i.CustomerID == customerId)
.Select new
{
//here you can select the fields which all are you required
}
要么
.Select new requireddatavm
{
//here you can select the fields which all are you required
}
在方法語法中,與其他運算符一起使用:
.Where(i => i.EmployeeID == employeeId && i.CustomerID == customerId)
,返回整個行,包括包含的字段
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.