Hello!

Seems to be a cartesian product, if you study the generated sql.

FetchMode.SubSelect should do the trick. Which version of NH are you
using?

If you can change the mappings, you could use set instead of bags.

Youd could also utilize Futures or multicriteria to load it all in one
roundtrip bur then you loose the hieracy, which I think could be
solved with resulttransformer.


On 13 Juni, 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
--~--~---------~--~----~------------~-------~--~----~
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