Hi Chris - I have the same issue.
One of the tricks I employ is to move closer to the "leaf" object.
In your case create your query on the EntrySplits:
EntrySplitCriteria esCrit = ....
esCrit.CreateAlias("Entry","e");
esCrit.Add(Restrictions.Eq("e.DatePosted", ...));
esCrit.SetFecthMode("RepTakes", FetchMode.Join);
esCrit.SetResultTransformer(new DistinctRootEntityResultTransformer
());
return esCrit.List<EntrySplit>().Select(x => x.Entry).Distinct();
Cheers,
Thomas
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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---