Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

nhibernate - What is the difference between JoinQueryOver and JoinAlias?

I need to know what is the difference between JoinQueryOver and JoinAlias, and when to use each?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Functionally they do the same thing, create a join to another entity. The only difference is what they return. JoinQueryOver returns a new QueryOver with the current entity being the entity joined, while JoinAlias returns the original QueryOver that has the current entity as the original root entity.

Whichever one you use is a matter of personal taste: (from http://nhibernate.info/doc/nh/en/index.html#queryqueryover)

IQueryOver<Cat,Kitten> catQuery =
    session.QueryOver<Cat>()
        .JoinQueryOver<Kitten>(c => c.Kittens)
            .Where(k => k.Name == "Tiddles");

and

Cat catAlias = null;
Kitten kittenAlias = null;
IQueryOver<Cat,Cat> catQuery =
    session.QueryOver<Cat>(() => catAlias)
        .JoinAlias(() => catAlias.Kittens, () => kittenAlias)
        .Where(() => kittenAlias.Name == "Tiddles");

Are functionally the same. Note how the kittenAlias is expressly referenced in the second query.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...