C#与SqlServer数据对照

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; }

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

参考

C# 数据类型与SqlServer对照

序号 类别 SQLServer C Sharp 备注
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
23 image
24 其他 uniqueidentifier Guid
25 Variant Object

C# 数据类型

类型 描述 范围 默认值
bool 布尔值 True 或 False FALSE
byte 8 位无符号整数 0 到 255 0
char 16 位 Unicode 字符 U +0000 到 U +ffff '\0'
decimal 128 位精确的十进制值,28-29 有效位数 (7.9×10287.9×1028)/10028 0.0M
double 64 位双精度浮点型 ±5.0×10324±1.7×10308 0.0D
float 32 位单精度浮点型 3.4×1038+3.4×1038 0.0F
int 32 位有符号整数类型 -2,147,483,648 到 2,147,483,647 0
long 64 位有符号整数类型 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 0L
sbyte 8 位有符号整数类型 -128 到 127 0
short 16 位有符号整数类型 -32,768 到 32,767 0
uint 32 位无符号整数类型 0 到 4,294,967,295 0
ulong 64 位无符号整数类型 0 到 18,446,744,073,709,551,615 0
ushort 16 位无符号整数类型 0 到 65,535 0
posted @   Kelvin's  阅读(172)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示