Hi,
Sql Server template maps integer column with type DECIMAL(5,0) to "decimal" type in .NET.
Is it possible to customize mapping so that DECIMAL(5,0) is mapped to "int32" and DECIMAL(9,0) to "int64"?
Looking for a working code similar to below, or another method:
foreach (var t in Tables.Values)
foreach (var c in t.Columns.Values)
{
if (c.DbType == System.Data.DbType.Decimal && c.Scale == 0) {c.DataType = typeof(Int32); }
}
GenerateModel();
Thank you.
One of the ways to do it is:
foreach (var t in Tables.Values)
foreach (var c in t.Columns.Values)
{
if (c.ColumnType == "decimal(5, 0)")
c.Type = c.IsNullable ? "int?" : "int";
else if (c.ColumnType == "decimal(9, 0)")
c.Type = c.IsNullable ? "long?" : "long";
}
Second one:
foreach (var t in Tables.Values)
foreach (var c in t.Columns.Values)
{
if (c.DataType == "DataType.Decimal" && c.Scale == 0)
{
if (c.Precision <= 5)
c.Type = "int" + (c.IsNullable ? "?" : "");
else
c.Type = "long" + (c.IsNullable ? "?" : "");
}
}
Gentlemen, thank you very much for advise, problem solved!