Ayende @ Rahien

It's a girl

NHibernate Tidbit – using 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.

Comments

Darren Thomas
04/26/2009 09:26 PM by
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
04/27/2009 03:12 AM by
Ayende Rahien

Darren,

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

Darren Thomas
04/29/2009 06:29 AM by
Darren Thomas

Good point :) this isn't a support forum

Thanks

cowgaR
05/12/2009 02:31 PM by
cowgaR

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?

thanks

Ayende Rahien
05/12/2009 03:10 PM by
Ayende Rahien

No,

because previous version had an explicit check which I removed

Comments have been closed on this topic.