Yuriy Vikulov
Yuriy Vikulov

Reputation: 2499

How to tell EF4 to load specific related objects?

For example, i have a class Unit it has one object City. Unit also has Category object. How to tell EF4 to load City object using this similar linq query, but not Category?

from u in db.Units orderby u.Name select u

Upvotes: 2

Views: 61

Answers (1)

ataddeini
ataddeini

Reputation: 4951

You can indicate that those should be included, like so:

from u in db.Units.Include("City") 
orderby u.Name 
select u

I believe this can also be done like this:

db.Units
   .Include(u => u.City)
   .OrderBy(u => u.Name);

Upvotes: 3

Related Questions