Phantom updates due to decimal precision on calculated properties

Posted by Jamie Ide on Stack Overflow See other posts from Stack Overflow or by Jamie Ide
Published on 2010-03-30T14:09:52Z Indexed on 2010/03/30 14:13 UTC
Read the original article Hit count: 351

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:

  1. Object is loaded with a property value of 14.9
  2. A calculation is performed and the property value is changed to 14.90393
  3. When the session is flushed, NHibernate issues an update because the property is dirty
  4. 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?

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about fluent-nhibernate