Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

NHibernate Tidbit – using <set/> without referencing Iesi.Collections

time to read 1 min | 117 words

Some people don’t like having to reference Iesi.Collections in order to use NHibernate <set/> mapping. With NHibernate 2.1, this is possible, since we finally have a set type in the actual BCL. We still don’t have an ISet<T> interface, unfortunately, but that is all right, we can get by with ICollection<T>.

In other words, any ISet<T> association that you have can be replaced with an ICollection<T> and instead of initializing it with Iesi.Collections.Generic.HashedSet<T>, you can initialize it with System.Collections.Generic.HashSet<T>.

Note that you still need to deploy Iesi.Collections with your NHibernate application, but that is all, you can remove the association to Iesi.Collections and use only BCL types in your domain model, with not external references.


Darren Thomas

I'm learning nHibernate so this is probably something I've done. When I replaced ISet with ICollection I noticed that I get an extra update after the insert statement when saving? If I replace ICollection with ISet the behaviour is as expected, a single insert statement.

What could be doing this?

Ayende Rahien


Please post everything (mapping, code & SQL) to the nh users mailing list

Darren Thomas

Good point :) this isn't a support forum



So in other words .NET 3.5 introduces HashSet <t but we still need to wait for the interface (.net 4.0 maybe) so we have an ICollection workaround.

Question is, why this works only with NH 2.1 (alpha currently)? Because of .NET 2.0 limitation of current NHibernate?


Ayende Rahien


because previous version had an explicit check which I removed

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats