This article describes my problem. I have several properties that are calculated. These are typed as decimal(9,2) in SQL Server and decimal in my C# classes. An example of the problem is:
- Object is loaded with a property value of 14.9
- A calculation is performed and the property value is changed to 14.90393
- When the session is flushed, NHibernate issues an update because the property is dirty
- Since the database field is decimal (9,2) the stored value doesn't change
Basically a phantom update is issued every time this object is loaded. I don't want to truncate the calculations in my business objects because that tightly couples them to the database and I don't want to lose the precision in other calculations. I tried setting scale and precision or CustomType("Decimal(9,2)") in the mapping file but this appears to only affect schema generation.
My only reasonable option appears to be creating an IUserType implementation to handle this. Is there a better solution?