天天看點

CSRobot gen:mssql-c#類型映射

  CSRobot的gen指令,有一個參數--map,是指資料庫字段類型到實體類型映射,本例是sql server到csharp的類型映射:

SQL Server C#
bigint Int64
binary Byte[]
bit Boolean
char String,Char[]
date  DateTime
datetime
datetime2
datetimeoffset DateTimeOffset
Decimal 小數
FILESTREAM  attribute (varbinary(max))

FLOAT

【-1.79E + 308 至 -2.23E - 308、0 以及 2.23E - 308 至 1.79E + 308】

Double

【±5.0 × 10−324 到 ±1.7 × 10308】

image
int Int32
money
nchar
ntext
numeric
nvarchar
real Single或float
rowversion
smalldatetime
smallint Int16
smallmoney
sql_variant Object 2
text
time TimeSpan
timestamp
tinyint Byte
uniqueidentifier Guid
varbinary
varchar
xml Xml

  在表格有“小數”字樣,這裡的意思是要根據資料庫定義的具體精度,轉換成對應的c#小數類型,下例是c#中三種小數類型的範圍和精度,共參考:

static void Main(string[] args)
 {
     Console.WriteLine("double:");
     double d1 = 0.0123456789012345678901234567890123456789d;
     Console.WriteLine(d1);
     double d2 = 1234567890123456789012345678901234567890.0123456789012345678901234567890123456789d;
     Console.WriteLine(d2);
     Console.WriteLine();
     Console.WriteLine("float:");
     float f1 = 0.0123456789012345678901234567890123456789f;
     Console.WriteLine(f1);
     float f2 = 123456789012345678901234567890123456789.0123456789012345678901234567890123456789f;
     Console.WriteLine(f2);
     Console.WriteLine();
     Console.WriteLine("decimal:");
     decimal m1 = 0.0123456789012345678901234567890123456789m;
     Console.WriteLine(m1);
     decimal m2 = 12345678901234567890123456789.0123456789012345678901234567890123456789m;
     Console.WriteLine(m2);
}      

結果:

double:

0.012345678901234568

1.2345678901234568E+39

float:

0.012345679

1.2345679E+38

decimal:

12345678901234567890123456789

  另外對于sqlserver中的一複雜類型,在c#中就得定義具體的實體類來對應了。

  想要更快更友善的了解相關知識,可以關注微信公衆号 

****歡迎關注我的asp.net core系統課程****

《asp.net core精要講解》 https://ke.qq.com/course/265696

《asp.net core 3.0》 https://ke.qq.com/course/437517

《asp.net core項目實戰》 https://ke.qq.com/course/291868

《基于.net core微服務》 https://ke.qq.com/course/299524

繼續閱讀