"design time settings are applied first, then run time settings are
applied."

Thanks for the response. I see that this is true, but what I'd like to
know is a) Why, and b) Can I override this behavior?

It seems obvious to me that users would usually want the Master-level
settings to override the Detail-level settings, regardless of which
ones are specified at run-time vs. design-time.

-- Brian



On May 10, 1: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].
> > 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].
> 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].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to