Entity Framework 即使指定了精度也会出现验证警告:XAF 日志
Entity Framework validation warning even though precision is specified: XAF Log
我的业务对象中有以下内容
using System.ComponentModel.DataAnnotations;
和
[ModelDefault("DisplayFormat", "{0:g}")]
[ModelDefault("EditMask", "g")]
[DataType("decimal(18,5)")]
public decimal Score { get; set; }
应用程序按预期运行,但在 eXpressAppFramework.log 我看到
Microsoft.EntityFrameworkCore.Model.Validation: Warning: No type was
specified for the decimal property 'Score' on entity type
'RatingEntry'. 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()'.
EF 只是不读取 DataTypeAttribute 作为其配置的一部分。使用 ColumnAttribute,例如
[Column(TypeName = "decimal(18,5)")]
配置Column Data Types。出现混淆是因为 System.ComponentModel.DataAnnotations 不仅仅用于 EF 实体注释。
我的业务对象中有以下内容
using System.ComponentModel.DataAnnotations;
和
[ModelDefault("DisplayFormat", "{0:g}")]
[ModelDefault("EditMask", "g")]
[DataType("decimal(18,5)")]
public decimal Score { get; set; }
应用程序按预期运行,但在 eXpressAppFramework.log 我看到
Microsoft.EntityFrameworkCore.Model.Validation: Warning: No type was specified for the decimal property 'Score' on entity type 'RatingEntry'. 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()'.
EF 只是不读取 DataTypeAttribute 作为其配置的一部分。使用 ColumnAttribute,例如
[Column(TypeName = "decimal(18,5)")]
配置Column Data Types。出现混淆是因为 System.ComponentModel.DataAnnotations 不仅仅用于 EF 实体注释。