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 at
http://groups.google.com/group/nhusers?hl=en.