How can I map MS SQL datatype numeric(19, 0) to .NET type
entity-framework, sql-server
Solution
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.
Problem
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.