Is it possible to do multiple joins to the same child collection with QueryOver? My Main reason for wanting to do this is to allow for the ability to construct some query which filters the parent via some property in on an element of a child collection and then proceed to eager load the collection for all parent's. In Linq this is easy as you can do the following
( from p in session.Query<Parent>() from child in p.Children where child.Property == "some value" select p ).Fetch(p => p.Children) and you end up with a SQL Query that joins to the Children table twice.. once for filtering and again for eager loading. Now with QueryOver this does not appear to be possible. If you simply do session.QueryOver<Parent>() .JoinQueryOver<Child>(p => p.Children) .Where(ch => ch.Property == "some value") .Fetch(p => p.Children).Eager .List() the SQL generated only does an inner join on the Children table which it filters correctly. Unfortunately this returns a result set where the Child Collection is not initialized. While the prescribed fix is to change the jointype to a left outer join, all this does is add the Children table's columns to the select statement. Since the joined Children Table was filtered only the filtered records are added to the Child Collection of the parent, not all of the Children Table records for each Parent. One way I have found around this issue is to place the filter into a detached query that projects the id's of the Parent records that meet the criteria, which is then used as a subquery filter to a different query whose sole purpose is to eager load all needed associations. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
