Reputation: 475
I have a relationship from Orders --> ContentRequest --> Institution table. How can I populate ContentRequest.Institution
while doing the database search?
This statement below will populate Orders
and the ContentRequest
model. This works fine.
List<Orders> orderList = db.Orders.Include("ContentRequest").ToList();
I would like to have the Orders.ContentRequest.Institution
model also populated.
Upvotes: 1
Views: 209
Reputation: 39366
You can do this (using this overload of Include extension method):
var orderList = db.Orders.Include(o=>o.ContentRequest.Institution).ToList();
Or you can still use the Include method you show in your question this way:
var orderList = db.Orders.Include("ContentRequest.Institution").ToList();
But I prefer the first solution because is strongly typed and in case you change the name of some property or you have some typing error writing the property names, with the first solution you will get a compile error.
Upvotes: 5