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 | DateTime |
datetime2 | DateTime |
datetimeoffset | DateTimeOffset |
Decimal | 小數 |
FILESTREAM ?attribute (varbinary(max)) | Byte[] |
FLOAT 【-1.79E + 308 至 -2.23E - 308、0 以及 2.23E - 308 至 1.79E + 308】 | Double 【±5.0 × 10?324?到 ±1.7 × 10308】 |
image | Byte[] |
int | Int32 |
money | 小數 |
nchar | String,Char[] |
ntext | String,Char[] |
numeric | 小數 |
nvarchar | String,Char[] |
real | Single或float |
rowversion | Byte[] |
smalldatetime | DateTime |
smallint | Int16 |
smallmoney | 小數 |
sql_variant | Object?2 |
text | String,Char[] |
time | TimeSpan |
timestamp | Byte[] |
tinyint | Byte |
uniqueidentifier | Guid |
varbinary | Byte[] |
varchar | String,Char[] |
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:
0.0123456789012345678901234568
12345678901234567890123456789
另外對于sqlserver中的一復雜類型,在c#中就得定義具體的實體類來對應了。
總結
以上是生活随笔為你收集整理的CSRobot gen:mssql-c#类型映射的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Dotnet的垃圾回收
- 下一篇: 从工作经历和实践理论看工业互联网的发展