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.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo