NHibernate 3. Alternatives to “ThenFetch” in QueryOver

ぐ巨炮叔叔 提交于 2019-12-02 23:24:15

I actually managed to solve this problem using two different approaches:

Approach one:

Session.QueryOver<Foo>().Fetch(x => x.A).Fetch(x => x.A.B).Fetch(x => x.A.B.C)

Approach two:

A a = null;
B b = null;
C c = null;

Session.QueryOver<Foo>()
    .JoinAlias(x => x.A, () => a)
    .JoinAlias(() => a.B, () => b)
    .JoinAlias(() => b.C, () => c)

Both work (altough I'm not exactly sure if one of them generated "inner" and the other one "outer" joins).

Just as a curiosity, I'll post the reply they gave me on the NHibernate Jira:

query 
    .Fetch(p => p.B) 
    .Fetch(p => p.B.C) // if B is not a collection ... or 
    .Fetch(p => p.B[0].C) // if B is a collection ... or 
    .Fetch(p => p.B.First().C) // if B is an IEnumerable (using .First() extension method) 

I think you can do that with JoinQueryOver

IQueryOver<Relation> actual =
   CreateTestQueryOver<Relation>()
    .Inner.JoinQueryOver(r => r.Related1)
    .Left.JoinQueryOver(r => r.Related2)
    .Right.JoinQueryOver(r => r.Related3)
    .Full.JoinQueryOver(r => r.Related4)
    .JoinQueryOver(r => r.Collection1, () => collection1Alias)
    .Left.JoinQueryOver(r => r.Collection2, () => collection2Alias)
    .Right.JoinQueryOver(r => r.Collection3)
    .Full.JoinQueryOver(r => r.People, () => personAlias); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!