开发者

NHibernate DistinctRootEntity Transformer For Sub-Collection

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.CreateCri开发者_开发问答teria(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!


I ended up writing an in-memory filter for child collections. NHibernate does not currently support the functionality I was looking for.

Thanks for looking.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜