【问题标题】:Entity Framework currency with 3 decimal places实体框架货币,小数点后 3 位
【发布时间】:2019-03-12 07:09:45
【问题描述】:

在 asp.net 5+ 中使用 EF6 代码优先,我如何存储具有 3 个小数点的十进制值?

即,我的字段需要能够存储 272.724

目前我有:

[DataType(DataType.Currency)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:c}")]
[DisplayName("Report Fee")]
public decimal ReportFee { get; set; }

我已经尝试添加:

[Column(TypeName = "decimal(18,3)")]

但我得到了错误:

The store type 'decimal(18,3)' could not be found in the SqlServer provider manifest

【问题讨论】:

  • 实体框架核心2?
  • 抱歉,应该是 EF6。
  • STORE,用于以后的计算
  • 这仍然是一个非常可疑的要求,应该在需要的地方和时间进行四舍五入,而不是在存储中。
  • 只要使用DataFormatString = "{0:c3}")

标签: c# asp.net entity-framework


【解决方案1】:

您可以尝试使用自定义约定。设置小数精度:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Properties<decimal>().Configure(config => config.HasPrecision(18, 3));
}

【讨论】:

猜你喜欢
  • 2015-11-21
  • 1970-01-01
  • 2012-09-04
  • 2020-12-06
  • 1970-01-01
  • 2016-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多