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

3

23

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

Synectics answered 10/2, 2012 at 2:48 Comment(1)
#6273136Rijeka
E
12

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.

Edmundson answered 10/2, 2012 at 2:52 Comment(0)
E
18

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.
Easygoing answered 10/2, 2012 at 4:20 Comment(1)
Hm, when I tried it, NHib for some reason was recreating my collection as an Array, so I could not add/remove items. It just looked at ICollection and decided that it can put whatever it likes...Profuse
E
12

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.

Edmundson answered 10/2, 2012 at 2:52 Comment(0)
C
6

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

Chiromancy answered 24/3, 2016 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.