1

From everything I understand, JoinAlias is supposed to be functionally similar to joinquery in all ways but the return object. IE JoinAlias returns the outer IQueryOver and the JoinQueryOver returns one for the join object. However in the following example:

    query.Left.JoinAlias(() => eventAlias.Children, () => childAlias);  

    query.Where(() => childAlias.Name.IsIn(SearchCriteria.SelectedNames.ToArray()));

The RowCount is 29.

But here:

  query.Left.JoinQueryOver(s => s.Children).Where(Restrictions.In(Projections.Property<Child>(x => x.Name),
                    SearchCriteria.SelectedNames.ToArray()));

query.RowCount(); returns 18.

The 18 is exactly what I want. There are 18 entries on the db.

I did some research on DistinctRootEntityResultTransformer() which brings the count to 14 after the alias, but this is still not correct.

On a high level I'd like to gain better understanding for what is happening, on an immediate level I'd like to know what to do about it if I need to use Alias.

Thanks

--- EDIT --- So This should be a left join, becuase count can be 0, and i just want the parent items. As noted in an answer, when I do run the exact same filter with the same join (left) the results are identical. However, when no one searches, I still create the alias, and without filtering at all I am getting 29.

Seth
  • 954
  • 1
  • 15
  • 42
  • I've deleted my answer for now-- have you tried using a profiler to see what SQL is being generated and comparing the two? – Andrew Whitaker Apr 29 '15 at 13:23
  • I'm working on that. I don't have nhibernate profiler set up on this machine. – Seth Apr 29 '15 at 13:27
  • 1
    @AndrewWhitaker I would say, there is no need to delete your answer, because it is definitely valid and related to one of the issues.. – Radim Köhler Apr 29 '15 at 13:48

1 Answers1

0

The first issue solved Andrew. The second is about Cartesian product.

Check this: NHibernate Fetch/FetchMany duplication in resultset, how to fix with ToFuture()

When we join root with children - result set gets multiplied. There will be as many rows as we have children. Not as many we have roots.

My suggestion would be, use batch-fetching to load collections ex-post, query just Root entity. To filter by Children, use sub-queries...

Check how to use batch fetching:

How to use subquery to filter just root:

How the distinct root entity works?

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335