2012-01-10 41 views
1

在我的數據庫中,我有一個Company。該公司有Branches,其中有一個Address。該公司也有Accounts,其中有ReturnAddresses,其中也有AddressEF4 Eager從嵌套表和共享表加載

我想急於負載在一個查詢所有這些數據,是這樣的:

from c in context.Company 
      .Include("Branches").Include("Address") 
      .Include("Accounts").Include("ReturnAddresses").Include("Address") 
where c.CompanyId.Equals(1)  
select c 

將兩個.Include("Address")方法計算自己獲得正確的地址,正確的方面?

如何在一個查詢中加載所有這些數據?

回答

3

在EF 4.1,你可以這樣做如下

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 
1

就像你在一個導航屬性等做使用點符號:

Include("Entity.Property")