nhibernate / nhibernate-core

NHibernate Object Relational Mapper
https://nhibernate.info
GNU Lesser General Public License v2.1
2.13k stars 925 forks source link

Loss of precision on decimal mapping - NHibernate 5 #3512

Closed walteralmeida closed 6 months ago

walteralmeida commented 6 months ago

I am using NHibernate 5 and seem to have a precision loss on decimal.

I have the following mapping :

<property name="Target80">
     <column name="`Target80`" sql-type="decimal (25, 23)" not-null="true" />
</property>

for a column defined in SQL SERVER as Decimal(25,23)

When I save data to the database, it only saves with precision 10

Saving the value "0.9987425544115787544545" result in "0.99874255440000000000000" in the database

hazzik commented 6 months ago

You should specify "precision" and "scale" attributes on the property/column, otherwise it would be treated with default .NET precision, which is 19-10.

<property name="Target80">
     <column name="`Target80`" sql-type="decimal (25, 23)" not-null="true" precision="25" scale="23" />
</property>
walteralmeida commented 6 months ago

Thank you, very helpful and solved my issue