2012-06-21 52 views
0
 // load the client and any many to one relationships 
     var clientRootQuery = session.QueryOver(() => clientAlias); 
     clientRootQuery.Left.JoinAlias(() => clientAlias.Person,() => personAlias) 
     .Left.JoinAlias(() => personAlias.SexType,() => sexTypeAlias) 
     .Left.JoinAlias(() => personAlias.EyeColorType,() => eyeColorTypeAlias) 
     .Left.JoinAlias(() => clientAlias.Organization,() => organizationAlias) 
     .Left.JoinAlias(() => clientAlias.ClientStatusType,() => clientStatusTypeAlias) 
     .Left.JoinAlias(() => clientAlias.Notes,() => noteAlias) 
     .Left.JoinAlias(() => noteAlias.Comments,() => commentAlias) 
     .Where(() => clientAlias.Id == clientId) 
     .Future<Client>(); 

     // load the note collection into the nhibernate session 
     // todo ******************** this doesn't work. nhibernate is still firing off queries in the adapter fill method rather than using the values pulled here. 
     var notes = session.QueryOver(() => clientAlias) 
     .Left.JoinAlias(() => clientAlias.Notes,() => noteAlias) 
     .Left.JoinAlias(() => noteAlias.Comments,() => commentAlias) 
     .Where(() => clientAlias.Id == clientId) 
     .Future<Client>(); 

return clientRootQuery.Take(1).SingleOrDefault(); 

這不會返回客戶端對象上的許多地址,也不會返回很多筆記。這應該工作。有許多筆記和許多地址的客戶。nHibernate多對多沒有獲取檢索對象上的子對象列表

任何想法?

回答

0
var clientRootQuery = session.QueryOver(() => clientAlias) 
     .Left.JoinAlias(() => clientAlias.Person,() => personAlias) 
     .Left.JoinAlias(() => personAlias.SexType,() => sexTypeAlias) 
     .Left.JoinAlias(() => personAlias.EyeColorType,() => eyeColorTypeAlias) 
     .Left.JoinAlias(() => clientAlias.Organization,() => organizationAlias) 
     .Left.JoinAlias(() => clientAlias.ClientStatusType,() => clientStatusTypeAlias) 
     .Where(() => clientAlias.Id == clientId) 
     .Future(); 

var notes = session.QueryOver(() => clientAlias) 
     .Left.JoinAlias(() => clientAlias.Notes,() => noteAlias) 
     .Where(() => noteAlias.Client.Id == clientId) 
     .Future(); 

var list = clientRootQuery.ToList(); 
     return list.FirstOrDefault(); 

它需要是一個左連接。

0

clientAddresses未初始化的原因是因爲您在它們上設置了一個過濾器,所以NHibernate假定並非所有clientAddresses都已加載完全初始化集合。

相關問題