How can I map MS SQL datatype numeric(19, 0) to .NET type [closed]

北慕城南 提交于 2020-02-20 09:24:19

问题


I am working on the mapping from MS SQL database to POCO classes:

I have numeric(19, 0), numeric(18, 0), numeric(3, 0), numeric(3, 0).

I am using the EF power tools to generate POCO and all map to decimal .NET C# Type.

But I think it should map to BigInt, Int64, Int32, Int16 etc.


回答1:


Here are the .NET integer types and their domains with maximum fitting numeric types:

  • SByte => -128 to 127 which fits up to NUMERIC(2, 0)
  • Int16 => -32,768 to 32,767 which fits up to NUMERIC(4, 0)
  • Int32 => -2,147,483,648 to 2,147,483,647 which fits up to NUMERIC(9, 0)
  • Int64 => -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 which fits up to NUMERIC(18, 0)

Since a decimal can hold up to 7.9*10^28, it fits up to NUMERIC(28, 0).

If you have an integer field bigger than NUMERIC(28, 0), you can use BigInteger in .NET 4.0 or newer.




回答2:


numeric(x, y) will be decimal. If you want int the correct type is:

SQL / C#

  • long / Int64
  • int / Int32
  • smallint / Int16


来源:https://stackoverflow.com/questions/20712663/how-can-i-map-ms-sql-datatype-numeric19-0-to-net-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!