nhibernate映射小数点具有精度和小数位数 [英] nhibernate mapping decimal with precision and scale

查看:283
本文介绍了nhibernate映射小数点具有精度和小数位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库内部,我的字段是decimal(9, 6)

inside db I have field which is decimal(9, 6)

Nhibernate会保存该数据,并保留最后一位数字,格式为decimal(9, 5)

Nhibernate save this data with losing last digit in format decimal(9, 5)

问题是如何使用nhib映射字段.通过代码映射以使用精度9,6

Question is how to map field using nhib. mapping by code to use precision 9,6

Property(
   x=>x.Longitude
   // precision and scale                  
);

推荐答案

您可以显式设置此类精度并按如下比例缩放

you can set explicitly to this type precision and scale like this

Property(
    x => x.Longitude,
    m =>
        {
            m.Precision(9);
            m.Scale(6);
        }
 );

或者您可以设置约定以匹配应用程序中的所有小数,这不在这个问题之内(只是一个主意).

or you can set in conventions to match all decimals in your app, this is outside of this question (just an idea).

希望这会有所帮助

这篇关于nhibernate映射小数点具有精度和小数位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆