Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 572
Tony Bao Avatar asked Dec 25 '22 15:12

Tony Bao


2 Answers

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.

like image 145
Gabe Avatar answered Mar 06 '23 22:03

Gabe


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

SQL / C#

  • long / Int64
  • int / Int32
  • smallint / Int16
like image 36
BrunoLM Avatar answered Mar 06 '23 22:03

BrunoLM