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 \times 10^{28} 到 7.9 \times 10^{28}) / 10^{0 到 28}$ | 0.0M |
double | 64 位双精度浮点型 | $ \pm 5.0 \times 10^{-324} 到 \pm 1.7 \times 10^{308} $ | 0.0D |
float | 32 位单精度浮点型 | $ -3.4 \times 1038 到 +3.4 \times 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 |