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.
Comments
blogs.msdn.com/.../...t-4-0-justin-van-patten.aspx
We may be getting an ISet <t interface in .net 4.
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?
Darren,
Please post everything (mapping, code & SQL) to the nh users mailing list
Good point :) this isn't a support forum
Thanks
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
No,
because previous version had an explicit check which I removed
Comment preview