Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding numeric type support for data api builder #2497

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Core/Models/SqlTypeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ public static class SqlTypeConstants
{ "datetime2", true }, // SqlDbType.DateTime2
{ "datetimeoffset", true }, // SqlDbType.DateTimeOffset
{ "", false }, // SqlDbType.Udt and SqlDbType.Structured provided by SQL as empty strings (unsupported)
{ "numeric", true} // Not present in SqlDbType, however can be returned by sql functions like LAG and should map to decimal.
};
}
6 changes: 5 additions & 1 deletion src/Core/Services/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static class TypeHelper
[SqlDbType.TinyInt] = typeof(byte),
[SqlDbType.UniqueIdentifier] = typeof(Guid),
[SqlDbType.VarBinary] = typeof(byte[]),
[SqlDbType.VarChar] = typeof(string)
[SqlDbType.VarChar] = typeof(string),
rohkhann marked this conversation as resolved.
Show resolved Hide resolved
};

private static Dictionary<SqlDbType, DbType> _sqlDbDateTimeTypeToDbType = new()
Expand Down Expand Up @@ -277,6 +277,10 @@ public static Type GetSystemTypeFromSqlDbType(string sqlDbTypeName)
return value;
}
}
else if (baseType.Equals("numeric", StringComparison.OrdinalIgnoreCase))
{
return typeof(decimal);
}

throw new DataApiBuilderException(
message: $"Tried to convert unsupported data type: {sqlDbTypeName}",
Expand Down