如何使用流畅的 NHibernate 将双精度数映射到十进制(x,y)?

问题描述 投票:0回答:1

我想映射一个双精度属性,以便可以将其值存储在 SQL Server(Express 版)中。默认映射将以 sql 浮点列结束。我想要有十进制(18,6)类型的数据库列。 但我的问题是我无法通过 Fluent Mapping 来完成它。根据映射语法,SQL 列的类型为 float 或decimal(18,0)。以下是我得到的总结:

Map(x => x.Quantity); ---> float

Map(x => x.Quantity).Precision(18).Scale(6); ---> float

Map(x => x.Quantity).CustomSqlType("decimal").Precision(18).Scale(6); ---> decimal(18,0)

映射双精度时如何设置精度和比例?

c# fluent-nhibernate
1个回答
0
投票

Fluent 在这方面非常字面意思 - 您只需将精度和小数位数添加到 CustomSqlType 语句中即可:

Map(x => x.Quantity).CustomSqlType("decimal(18,6)");

© www.soinside.com 2019 - 2024. All rights reserved.