且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

实体框架核心 - 将十进制精度和比例设置为所有十进制属性

更新时间:2023-02-14 21:06:07

你已经很近了这是代码。

You got close. Here's the code.

foreach (var property in modelBuilder.Model.GetEntityTypes()
    .SelectMany(t => t.GetProperties())
    .Where(p => p.ClrType == typeof(decimal)))
{
    property.Relational().ColumnType = "decimal(18, 6)";
}