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.