gpt4 book ai didi

c# - 如何更改 Fluent NHibernate 中小数的默认比例和精度?

转载 作者:太空狗 更新时间:2023-10-29 18:20:59 27 4
gpt4 key购买 nike

在我正在构建的应用程序中,我有许多需要从数据库映射的具有特定精度和小数位数的小数字段。我可以通过使用 Precision()Scale() 方法来实现:

public class ClassAMap : ClassMap<ClassA>
{
public ClassAMap ()
{
Map(x => x.Value).Precision(22).Scale(12);
}
}

有什么方法可以更改小数的默认精度和小数位数,这样我就不需要记住添加对 Precision()Scale() 的调用> 对于映射的每个小数?

最佳答案

您可以定义一个 PropertyConvention。以下是总体思路。 (未测试)

public class DecimalConvention : IPropertyConvention
{
public void Apply(IPropertyInstance instance)
{
if (instance.Type == typeof(decimal) || instance.Name == "Value") //Set the condition based on your needs
{
instance.Precision(22).Scale(12);
}
}
}

确保在配置 Fluent 时包含此约定。

关于c# - 如何更改 Fluent NHibernate 中小数的默认比例和精度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5426496/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com