在不使用属性的情况下指定小数精度的最佳方法是什么。
我只需要在我的 Data.Models 中将所有小数设置在一个位置。其繁琐的为每个小数指定属性。
public class Customer
{
public int customerId{ get; set; }
[Column(TypeName = "decimal(18,2)")]
public decimal AvailableAmount{ get; set; }
}
最佳答案
将以下内容添加到 OnModelCreating
dbcontext 中的方法:
protected override void OnModelCreating(ModelBuilder builder)
{
foreach (var property in builder.Model.GetEntityTypes()
.SelectMany(t => t.GetProperties())
.Where(p => p.ClrType == typeof(decimal) || p.ClrType == typeof(decimal?)))
{
property.Relational().ColumnType = "decimal(18,2)";
}
}
关于c# - 验证 30000 没有为小数列指定类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62550667/