C#与SqlServer数据对照

发布时间 2023-10-10 12:08:07作者: Kelvin's

Decimal报错:

No store type was specified for the decimal property 'GridElectricityPurchase' on entity type 'ChargeDischarge'. 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'.

给报错的属性添加注解

[Column(TypeName = "decimal(18,2)")]
    public decimal ChargeCapacity { get; private set; }

这样在进行数据库迁移的时候就不会报错了

参考

1 整数 bit Boolean True转换为1False转换为0
2 tinyint Byte C Sharp 数据类型都位于System命名空间
3 smallint Int16
4 int Int32
5 bigint Int64
6 smallmoney Decimal
7 money Decimal
8 numeric Decimal
9 decimal Decimal
10 浮点数 float Double
11 real Single
12 日期和时间 smalldatetime DateTime
13 datetime DateTime
14 timestamp DateTime
15 字符串 char String
16 text String
17 varchar String
18 nchar String
19 ntext String
20 nvarchar String
21 二进制数据 binary Byte[]
22 varbinary Byte[]
23 image Byte[]
24 其他 uniqueidentifier Guid
25 Variant Object