c# - populating sub object using linq -
i have relationship orders --> contentrequest --> institution table. how can populate contentrequest.institution
while doing database search?
this statement below populate orders
, contentrequest
model. works fine.
list<orders> orderlist = db.orders.include("contentrequest").tolist();
i have orders.contentrequest.institution
model populated.
you can (using overload of include extension method):
var orderlist = db.orders.include(o=>o.contentrequest.institution).tolist();
or can still use include method show in question way:
var orderlist = db.orders.include("contentrequest.institution").tolist();
but prefer first solution because typed , in case change name of property or have typing error writing property names, first solution compile error.