2010-10-22 36 views
1

我有一個使用ICriteria API從NHibernate調用返回的根實體集合(IList<RootEntity>)。 RootEntity有一個子實體的集合,讓我們打電話IList<Child1Entity>Child1Entity有一個子實體集合(IList<Child2Entity>),它是第三層,導致Child1Entity集合有重複。對於子集合NHibernate DistinctRootEntity轉換器

我的問題是如何將重複刪除過程應用到子集合。

我有重複的原因是因爲我在子集合上使用LeftOuterJoin。我無法刪除LeftOuterJoin。

每個子表都使用下面的代碼加入:

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); 

謝謝!

+0

你能顯示代碼嗎?你不應該在兒童收藏中有任何重複,除非你沒有告訴我們其他的東西。 – 2010-10-22 18:07:44

+0

更新了我的問題。還有一層兒童,我忘了在問題中提到。 – a432511 2010-10-22 18:39:35

回答

-1

我最終爲子集合寫了一個內存中的過濾器。 NHibernate目前不支持我正在尋找的功能。

感謝您的期待。

+0

你可以請你發佈你的代碼嗎? – 2013-07-09 21:43:47