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

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.

Print | posted on Thursday, April 23, 2009 6:11 AM

Feedback


Gravatar

# re: NHibernate Tidbit – using <set/> without referencing Iesi.Collections 4/23/2009 4:49 PM James

blogs.msdn.com/.../...t-4-0-justin-van-patten.aspx

We may be getting an ISet interface in .net 4.


Gravatar

# re: NHibernate Tidbit – using <set/> without referencing Iesi.Collections 4/27/2009 12:26 AM 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?


Gravatar

# re: NHibernate Tidbit – using <set/> without referencing Iesi.Collections 4/27/2009 6:12 AM Ayende Rahien

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


Gravatar

# re: NHibernate Tidbit – using <set/> without referencing Iesi.Collections 4/29/2009 9:29 AM Darren Thomas

Good point :) this isn't a support forum

Thanks


Gravatar

# re: NHibernate Tidbit – using <set/> without referencing Iesi.Collections 5/12/2009 5:31 PM cowgaR

So in other words .NET 3.5 introduces HashSet 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?

thanks


Gravatar

# re: NHibernate Tidbit – using <set/> without referencing Iesi.Collections 5/12/2009 6:10 PM Ayende Rahien

No,
because previous version had an explicit check which I removed

Comments have been closed on this topic.