NHibernate: References still being eagerly selected after specifying AddJoin

Posted by cbp on Stack Overflow See other posts from Stack Overflow or by cbp
Published on 2010-05-07T08:36:17Z Indexed on 2010/05/07 8:38 UTC
Read the original article Hit count: 169

Filed under:

I have a query which is something like this:

Session.CreateSQLQuery(
    @"SELECT f.*, b.*, z.* FROM Foo f
     LEFT OUTER JOIN Bar b ON b.Id = f.BarId
     LEFT OUTER JOIN Zar z ON z.Id = b.ZarId"
     )
    .AddEntity("f", typeof(Foo))
    .AddJoin("b", "f.BarId")
    .AddJoin("z", "f.ZarId")
    .List<Foo>();

The problem is that I am still getting hundreds of SELECT requests made to the Zar table, even though I have specified that Zar should be joined.

As far as I am aware the only relationship is Foo->Bar->Zar, i.e. the reference to Zar is not occurring anywhere else.

Is my understanding of AddJoin correct? What could be going wrong?

  1. List item

© Stack Overflow or respective owner

Related posts about nhibernate