开发者

NHibernate 3.0 rounding a decimal to 5 decimal places - why?

开发者 https://www.devze.com 2023-02-15 21:40 出处:网络
All, We were using NHiberate 2.1 where we are storing decimal values (exchange rates) e.g. 123.1234567 to 7 decimal places

All,

We were using NHiberate 2.1 where we are storing decimal values (exchange rates) e.g. 123.1234567 to 7 decimal places

We are mapping the type using default mapping style:

<property name="ExchangeRate"  not-null="true" />

However when we upgrade to NHibernate 3.0 the value above is saved as 123.1234500.

It does not specify this change in behaviour in the 3.0 release notes although it does seem to detail that in issue [NH-1594], the default value for decimal is DECIMAL(19,5)

We have a solution i.e. specify the following mapping:

<pro开发者_Go百科perty name="ExchangeRate"  type="decimal(10,7) not-null="true" />

I need to know is this solution the right way to solve this issue? Also, why is there a functional change in behaviour with rounding between 2.1 and 3.0?

Cheers,

Billy Stack


That works, but this is cleaner IMO:

<property name="ExchangeRate" precision="10" scale="7" />

A not-null decimal is implied by the property type.


This solution unfortunately doesn't work if you have to specify default value that can be set on the column tag only.

<property name="Price" precision="25" scale="8" not-null="true">
  <column name="Price" default="1"/>
</property>

You have to move everything to the column tag to make it work.

<property name="Price">
  <column name="Price" default="1" precision="25" scale="8" not-null="true"/>
</property>
0

精彩评论

暂无评论...
验证码 换一张
取 消