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

dan_l picture dan_l · Feb 10, 2012 · Viewed 9.2k times · Source

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

Answer

Jamie Ide picture Jamie Ide · Feb 10, 2012

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.