SQL Server Type Mappings has the information you require.
I've started looking at building it dynamically by switching on the
SqlDbType
to determine if i need to use the Size property etc however this is very long-winded and error prone.
It's unlikely you can improve upon this, the page says this much:
SQL Server and the .NET Framework are based on different type systems. For example, the .NET Framework Decimal structure has a maximum scale of 28, whereas the SQL Server decimal and numeric data types have a maximum scale of 38
For the example of Decimal
and decimal
, you could always fix the scale at 28. That is, always take the highest precision required and do not try to vary it.