Can .NET 4 ISet<> HashSet<> replace NHibernate Iesi.Collections ISet , HashSet?

。_饼干妹妹 提交于 2019-12-09 05:14:12

问题


Can .NET 4 ISet<> HashSet<> replace NHibernate Iesi.Collections ISet , HashSet ? I am using Castle proxy, and NHibernate 3.0 .


回答1:


No, not as of this reply.

The NHibernate engine uses the Iesi.Collections.ISet interface on internal collection classes which are used as wrappers around collections in your classes which NHibernate persists. There is no direct conversion to System.Collections.Generic.ISet<T>.

Update: NHibernate 4 now uses HashSet<T> from the BCL internally, and HashedSet<T> has been removed from the Iesi.Collections dependency. The approach to use System.Collections.Generic.ISet<T> is now available.




回答2:


Yes. There are two approaches:

  1. Declare your collection as ICollection<T> and initialize it as HashSet<T>. See this article. I model collections as private members and expose IEnumerable<T> so this works well, but the downside is that you can't expose ISet<T>.
  2. Use Jose Romaniello's Set4Net4 NuGet package. See this article and the source code.



回答3:


Yes, with Nhibernate 4, using System.Collections.Generic.ISet<> is now the way to go.



来源:https://stackoverflow.com/questions/9222058/can-net-4-iset-hashset-replace-nhibernate-iesi-collections-iset-hashset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!