You could create a custom user type that maps 0 to NULL and vice-versa. then your mapping files just specifies your custom user type. You could either inherit from NHibernate.Type.Int32Type, or implement NHibernate.IUserType from scratch. For our user types, we implemented the interface, and used composition rather than inheritance.
Using composition, we simply forwarded access to the SqlTypes property, DbTypes property, IsMutable method and DeepCopy method. Then just implement your own logic for the Equals, NullSafeSet and NullSafeGet methods. NullSafeSet and NullSafeGet can just map 0 to NULL and vice-versa before or after calling the base method, as appropriate. Equals can consider 0 equal to NULL.
|