On both my latest contract and an open source project I am working on we are using both .NET 2.0 and NHibernate. While NHiberate works just fine with 2.0, there is no native support for nullable types. There are some nullable types built into NHibernateContrib, but we would have to use their types instead of the normal .NET 2.0 types… this seemed like a bad solution. We tried a couple different options, but finally ended up with modifying the NHibernateContrib types to use the native .NET 2.0 types. I made a couple other small changes to the contrib code as well. Now you can do this in your mapping file:
The property TestBool is declared as “bool?” in the class, not a special nullable type.
This is really just a temporary solution until NHibernate is revised to include native support for these types, but if you are running into the same problems feel free to download it and give it a try. (let me know if you find any bugs or have any fixes)
Thanks for providing this library. I have found this to be the most elegant solution to handling nullables in .NET 2.0. The Nullables library that comes with NHibernateContrib does not serialize well over a Web Service. On the other hand, .NET 2.0 nullable are correctly supported by Web Services so your library is a perfect complement for NHibernate.
BTW, I have contributed an NHibernate cartridge to the AndroMDA project which demonstrates the use of Nullables2 in a sample application. AndroMDA along with my NHibernate cartridge allows developers to generate large portions of the data access layer using a UML model as the input. If you are anyone watching this post is interested, see the links below for more details. This stuff can save you hours or even days of work!