EF Core 6 小数精度警告

sof*_*ntp 19 entity-framework-core

升级到 EF Core 6 后,在添加迁移时,我遇到了这个恼人的警告:

No store type was specified for the decimal property '{property}' on entity type '{entityType}'. This will cause values to be silently truncated if they do not fit in the default precision and scale. Explicitly specify the SQL server column type that can accommodate all the values in 'OnModelCreating' using 'HasColumnType', specify precision and scale using 'HasPrecision', or configure a value converter using 'HasConversion'.
Run Code Online (Sandbox Code Playgroud)

此处定义: https: //github.com/dotnet/efcore/blob/main/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs

我不确定是否理解此警告的目的,因为带有标签的实体 [Keyless]并不存在于数据库中。另外添加诸如 之类的属性似乎 [Column(TypeName = "decimal(28, 6)")]并不能清除有关无密钥实体的警告。

Rya*_*ato 25

显然EF Core 6有一个新属性:

using Microsoft.EntityFrameworkCore;

...

[Precision(18, 2)]
Run Code Online (Sandbox Code Playgroud)