Hi Ken
Thanks for the suggestion. I currently have the following, which works:
var parent = session.CreateCriteria(typeof (Parent))
.Add(Restrictions.IdEq(id))
.UniqueResult<Parent>();
var versions = session.CreateCriteria(typeof (ParentVersion))
.Add(Restrictions.Eq("Parent.Id", id))
.SetFetchMode("Associations", FetchMode.Join)
.SetResultTransformer(new
DistinctRootEntityResultTransformer())
.List<ParentVersion>();
parent.Versions = versions;
This results in two sql statements (as expected), and the distinct
transformer does remove the duplicates from the version list. In a perfect
world I'd still like just one big sql statement without the duplicates, but
that is not serious. I do wonder if i could merge the above seperate
criteria into one, but I'll keep hacking some other day.
I did try to use MultiCriteria like so:
var parentCrit = session.CreateCriteria(typeof(Parent))
.Add(Restrictions.IdEq(id));
var versions = session.CreateCriteria(typeof (ParentVersion))
.Add(Restrictions.Eq("Parent.Id", id))
.SetFetchMode("Associations", FetchMode.Join)
.SetResultTransformer(new
DistinctRootEntityResultTransformer());
IMultiCriteria multiCriteria = session.CreateMultiCriteria()
.Add(parentCrit)
.Add(versions);
IList results = multiCriteria.List();
Parent parent = (Parent)((ArrayList)results[0])[0];
ArrayList list = (ArrayList)results[1];
Interestingly the list at the end still had the duplicates - it seems the
ResultTransformer does not work within MultiCriteria? I'm also not that
excited by having to loop through the arraylist to build a generic IList, so
I'll likely just stick to the first solution.
Thanks again.
Ben
2008/9/14 Ken Egozi <[EMAIL PROTECTED]>
> try to fetch the associations in a separate criteria (use MultiCriteria to
> have it done in a single roundtrip)
> NH should be able to wire everything up.
>
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---