c# - 我如何从孙子那里获取数据?

标签 c# entity-framework

我有 EF 3.5,我正在尝试从 3 个不同的实体获取信息。
orders 有到 orderitems 的导航,orderitems 有到 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

最佳答案

您可以尝试如下所示。

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

关于c# - 我如何从孙子那里获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39517562/

相关文章:

asp.net-mvc-3 - 使用 ninject 注入(inject)对模型类或非 Controller 类的依赖

entity-framework - 如何实现 IDbContextFactory 以与 Entity Framework 数据迁移一起使用

sql-server - 如何将存储函数添加到 Entity Framework

c# - UserControl 中的 Web 控件是否为空?

c# - 目录为空时报错 "The directory is not empty."

c# - Moq It.IsAnyType 不适用于具有泛型类型返回任务的 Func

c# - Entity Framework 主键异常

.net - Entity Framework 6 - 在插入和并发之前检查记录是否存在

c# - 如何在 dateTime 中转换字符串日期?

c# - Azure函数 "Unable to find assembly"