Reputation: 6884
In my database I have a Company
. The company has Branches
, which have an Address
. The company also has Accounts
, which have ReturnAddresses
, which also have an Address
.
I want to eager load all this data in one query, something like:
from c in context.Company
.Include("Branches").Include("Address")
.Include("Accounts").Include("ReturnAddresses").Include("Address")
where c.CompanyId.Equals(1)
select c
Will the two .Include("Address")
methods figure themselves to get the right addresses for the right aspects?
How else can I load all this data in one query?
Upvotes: 1
Views: 596
Reputation: 32437
In EF 4.1 you can do so as follows
from c in context.Company
.Include(c => c.Branches.Select(b => b.Address))
.Include(c => c.Accounts.Select(a => a.ReturnAddresses.Select(r => r.Address)))
where c.CompanyId.Equals(1)
select c
Upvotes: 3
Reputation: 4504
Use a dot notation like you do on a navigation property so:
Include("Entity.Property")
Upvotes: 1