2011-08-12 93 views
1

任何人都可以解釋爲什麼這個查詢將返回12家公司(有12名UserAccessList兒童)NHibernate的取返回多個父對象

var list = session.QueryOver<Company>() 
     .Where(x => x.Id == 1) //x => x.Id.IsIn(ids)) 
     .Fetch(l => l.UserAccessList).Eager() 
     .List<Company>(); 
+0

見這個問題的答案 http://stackoverflow.com/questions/6221362/am-i-doing-something-wrong-with-nhibernate-query-over-fetch/6224217#6224217 – hazzik

回答

2

因爲在SQL它的將是這樣的:

select * from 
Companies c left outer join UserAccessLists uac on c.Id == uac.CompanyId 
where c.id = id 

它在結果中給出重複。如何解決這些問題,你可以閱讀here

1

這也適用

var c = session.QueryOver<Company>() 
     .Future(); 

session.QueryOver<Company>() 
     .Fetch(l => l.UserAccessList).Eager() 
     .Future(); 

var list = c.ToList(); 
相關問題