2012-12-19 122 views
0
class parent 
{ 
virtual AnotherType AnotherType {get;set;} 
virtual TypeA TypeA {get;set;} 
virtual IList<TypeB> TypeBs {get;set;} 
} 

class TypeA 
{ 
virtual TypeC TypeC {get;set;} 
... 
} 

class TypeB 
{ 
virtual TypeD TypeD {get;set;} 
... 
} 

需要通過過濾的類型A和類型B流利NHibernate的過濾器和項目的收集和關聯

select p.* 
from parent p 
join typea a on a.parentid = p.parentid 
join typeb b on b.parentid = p.parentid 
join typec c on c.typeaid = c.typeaid 
join typed d on d.typebid = d.typebid 
where p.AnotherType.id = "someid" 
and c.foo == "foo" 
and d.bar == "bar" 

回到父母的截然不同的列表嘗試使用

Session.QueryOver(() => parent) 
.joinalias(() => parent.TypeA,() => typea) 
.joinalias(() => typea.TypeC,() => typec) 
.joinalias(() => parent.TypeB,() => typeb) 
.joinalias(() => typeb.TypeD,() => typed) 
.where(() => parent.AnotherType.id == "someid") 
.and(() => typec.foo == "foo") 
.and(() => typed.bar == "bar).Future<parent>.ToArray(); 

,但我發現重複因爲typeB會變成結果而不是單獨作爲父級集合查詢。

回答

0

濾波器

Session.QueryOver(() => parent) 
    ... 
    .TransformUsing(Transformers.DistinctRootEntity) 
    .Future<Parent>().ToArray(); 
重複的