I have a collection of Root Entities (IList<RootEntity>
) that is returned from an NHibernate call using the ICriteria API. RootEntity
has a collection of child entities, lets call that IList<Child1Entity>
. Child1Entity
has a collection of child entities (IList<Child2Entity>
), which, being the third layer, causes the Child1Entity
collection to have duplicates.
My question is how can I apply the de-duplication process to the child collection.
The reason I have duplicates is because I am using LeftOuterJoin on the child collections. I cannot remove the LeftOuterJoin.
Each of the sub-tables are joined using the following code:
ICriteria rootCriteria = session.CreateCriteria(typeof(RootEntity));
rootCriteria.CreateCriteria("Child1Collection", "Child1CollectionAlias", NHibername.SqlCommand.JoinType.LeftOuterJoin);
rootCriteria.CreateCriteria("Child1CollectionAlias.Child2Collection", "Child2CollectionAlias", NHibername.SqlCommand.JoinType.LeftOuterJoin);
rootCriteria.Add(Expression.Eq("Child2CollectionAlias.Property", value));
rootCriteria.SetResultTransformer(DistinctRootEntity);
Thanks!