• CSRobot gen:mssqlc#类型映射


      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#中就得定义具体的实体类来对应了。

      想要更快更方便的了解相关知识,可以关注微信公众号 
     

     

  • 相关阅读:
    Zabbix监控系统系列之二 : 初始化配置
    docker中的zabbix 配置钉钉机器人
    sqldbx 绿色小巧的数据库查询管理工具
    Windows 10 自建Anki 私有云服务器
    Sqlserver内存管理:限制最大占用内存
    tfs强制撤销其他工作区挂起更改,删除工作区
    easyui的一些文档
    IIS下日志分析
    zookeeper-client
    Windbg程序调试系列-索引篇(转)
  • 原文地址:https://www.cnblogs.com/axzxs2001/p/15862458.html
Copyright © 2020-2023  润新知