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;}
...
}
需要通过过滤 TypeA 和 TypeB 返回不同的父列表
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 被扁平化为结果,而不是作为父集合单独查询。