[英]Entity Framework Include and Select are gettind some other entities
I am using Entity Framework 6 latest stable version with Northwind database. 我正在使用带有Northwind数据库的Entity Framework 6最新稳定版本。 And I wrote a query like below. 我写了一个查询,如下所示。 Even I didn't include customer to order. 甚至我也没有包括要订购的客户。 And also included entity OrderDetails has Order (this is like recursion). 并且还包括实体OrderDetails具有Order(这类似于递归)。 And the final included entity Product of OrderDetails has Category even I didn't include. 最终包含的OrderDetails实体产品甚至具有我未包含的类别。 The weird thing is Supplier is a navigation property but it is null for product. 奇怪的是,供应商是一个导航属性,但对于产品则为null。
Plus : LazyLoading and ProxyCreationEnabled is false 另外: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();
And OrderDetail's issue 和OrderDetail的问题
What I can't catch on this? 我无法理解的是什么?
you can put a select if you dont want unwanted data from table.you can do by anonymous select or using view-model Class 如果您不想从表中获取不需要的数据,则可以进行选择。您可以通过匿名选择或使用视图模型类来进行选择
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
}
or 要么
.Select new requireddatavm
{
//here you can select the fields which all are you required
}
In method syntax, with other operators: 在方法语法中,与其他运算符一起使用:
.Where(i => i.EmployeeID == employeeId && i.CustomerID == customerId)
, returns the whole row including included fields ,返回整个行,包括包含的字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.