Tolomaüs, lazy should hit the moment.
subselect should hit only the way.

2009/6/20 Tolomaüs <[email protected]>

>
> Hi Chris,
>
> You can set the fetchmode of the collections to "subselect" in the
> mapping files. Don't forget to do an NHibernateUtil.Initialize on both
> collections after you execute the query, because subselects are always
> considered lazy (at least, that's my understanding).
>
> Hope this helps,
>
> Tolomaüs.
>
> On 13 jun, 03:00, Chris Nicola <[email protected]> wrote:
> > I have a hierarchy of one-to-many relationship that is as follows:
> >
> > Entries --> EntrySplits --> RepTakes
> >
> > Each collection uses <bag>
> >
> > It is difficult to create a query on Entries that eagerly loads Splits
> and
> > Takes and returns unique results.
> >
> > For example:
> >
> >             var criteria = session.CreateCriteria(typeof (T), "entries")
> >                 .SetFetchMode("entries.EntrySplits", FetchMode.Join)
> >                 .SetFetchMode("entries.EntrySplits.RepTakes",
> > FetchMode.Join);
> >
> >             var restrictions = Restrictions.Disjunction();
> >             if (IsClosed.HasValue && IsClosed.Value)
> >             {
> >
> > restrictions.Add(Restrictions.IsNotNull("entries.DateClosed"));
> >             }
> >             else if (IsClosed.HasValue && !IsClosed.Value)
> >             {
> >
> restrictions.Add(Restrictions.IsNull("entries.DateClosed"));
> >             }
> >             if (StartDate != null)
> >                 restrictions.Add(Restrictions.Gt("entries.DatePosted",
> > StartDate));
> >             if (EndDate != null)
> >                 restrictions.Add(Restrictions.Lt("entries.DatePosted",
> > EndDate));
> >             if (IsDebit != null)
> >                 restrictions.Add(Restrictions.Eq("entries.IsDebit",
> > IsDebit.Value));
> >
> > criteria.SetResultTransformer(CriteriaSpecification.DistinctRootEntity);
> >             return criteria.Add(restrictions).List<T>();
> >
> > Successfully returns unique results for the Entries, however wherever
> there
> > are multiple RepTakes I get non-unique EntrySplits.  Is there some way to
> > apply DistinctRootEntity to the second level?  I have tried several
> > approaches but with no luck so far.
> >
> > Obviously I can filter the results after they are returned but somehow
> that
> > feels ugly to me.
> >
> > Related to this, why is there no FetchMode.Subselect?  It seems like it
> > would be an obvious and ideal solution to the problem.
> >
> > Thanks,
> > Chris
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
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