I meant this one... Sorry for the mix up. http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx
On Tue, May 11, 2010 at 6:06 AM, Jason Dentler <[email protected]>wrote: > This may help: > > http://ayende.com/Blog/archive/2009/04/27/nhibernate-futures.aspx > > > On Mon, May 10, 2010 at 12:18 PM, Jason Meckley <[email protected]>wrote: > >> the problem isn't NH the problem is how you have configured NH. design >> time settings are applied first, then run time settings are applied. >> you have also configured your Details to be eagerly loaded. therefore >> when you select Master, Details will be selected using an outer-join >> and the records will be sorted by date, then any other properties you >> choose. >> >> I would remove the ordering and lazy loading from the mapping and >> apply this to the query at runtime. you can reduce the duplication by >> using either a named query or subclassing DetachedCriteria. >> >> "When I fetch masters, I want the details to come along with them >> eagerly. >> ... >> I'm very tempted to throw in a "duh!" here and rant about the >> perversity of NHibernate's need to fetch masters and details in a >> single join query, but I will resist." >> eager loading means an outer join >> lazy is additional selects. >> >> >> >> On May 10, 11:52 am, Brian Berns <[email protected]> wrote: >> > I have two entities called Master and Detail. When I fetch masters, I >> > want the details to come along with them eagerly. This is a perfect >> > case for DistinctRootEntityResultTransformer. >> > >> > The details are always sorted by datetime, so I mark this on the >> > association in the mapping file: >> > >> > <bag name="Details" order-by="Date" lazy="false"> >> > <key column="MasterFK"/> >> > <one-to-many class="Detail"/> >> > </bag> >> > >> > When I fetch the masters, I want to sort them by name, so I specify >> > this when creating the criteria: >> > >> > session.CreateCriteria<Master>() >> > .SetFetchMode("Details", FetchMode.Join) >> > .SetResultTransformer(new >> > DistinctRootEntityResultTransformer()); >> > .AddOrder(Order.Asc("Name")) >> > .List<Master>(); >> > >> > The problem with this is that the results come back sorted first by >> > Detail.Date, then secondly by Master.Name. Here's the SQL: >> > >> > ORDER BY details2_.Date, this_1_.Name asc >> > >> > This is clearly not what I want. (I'm very tempted to throw in a >> > "duh!" here and rant about the perversity of NHibernate's need to >> > fetch masters and details in a single join query, but I will resist. >> > I... will... resist...) >> > >> > So, how do I tell NHibernate to sort the masters before sorting the >> > details? >> > >> > -- >> > 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]<nhusers%[email protected]> >> . >> > For more options, visit this group athttp:// >> groups.google.com/group/nhusers?hl=en. >> >> -- >> 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]<nhusers%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/nhusers?hl=en. >> >> > -- 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.
