如何从孙子孙女那里获取数据?

时间:2016-09-15 18:03:06

标签: c# entity-framework

我有EF 3.5,我试图从3个不同的实体获取信息 orders导航为orderitemsorderitems导航至ProductSize,导航至Product。当我使用.Include语句将其他实体添加到Orders时,问题就出现了,返回仅显示来自Orders的数据,而不显示来自任何其他实体的数据。

这是样本

var query = (from c in context.Orders
.Include("OrderItems")
.Include("OrderItems.ProductSize:)
.Include("OrderItems.ProductSize.Product)

select c).ToList()

Order

OrderID
Comments
EDIPI
IssuedDate
OrderItems Navigation
ShippingLocation Navigation

OrderItem

OrderItemID
Quantity
Issued
Order Navigation
ProductSize Navigation

ProductSize

ProductSizeID
Size
NSN
Price
Items Navigation
Product Navigation
OrderItems Navigation

1 个答案:

答案 0 :(得分:0)

您可以尝试如下所示。

var query = (from c in context.Orders select c)
            .Include(oi=>oi.OrderItems.Order)
            .Include(o=>o.OrderItems.ProductSize.Product)
            .ToList();