标签: c# linq
我与订单有关系 - > ContentRequest - >机构表。如何在进行数据库搜索时填充ContentRequest.Institution?
ContentRequest.Institution
以下声明将填充Orders和ContentRequest模型。这很好。
Orders
ContentRequest
List<Orders> orderList = db.Orders.Include("ContentRequest").ToList();
我想填充Orders.ContentRequest.Institution模型。
Orders.ContentRequest.Institution
答案 0 :(得分:5)
你可以这样做(使用Include扩展方法的重载):
var orderList = db.Orders.Include(o=>o.ContentRequest.Institution).ToList();
或者您仍然可以使用您在问题中显示的Include方法:
var orderList = db.Orders.Include("ContentRequest.Institution").ToList();
但是我更喜欢第一种解决方案,因为它是强类型的,如果你更改了某些属性的名称,或者你在编写属性名时有一些输入错误,使用第一种解决方案就会出现编译错误。