Reputation: 1842
I have a SQL table which has several large decimal values in them. Too large to use decimals
in my model. However when I use double
I get an Invalid Operation Exception
which states that it was unable to convert System.Decimal
to System.Double
.
I'm using EntityFramework Core in a .Net Core 2.2 application. Is there a way to specify to my DbContext that it should grab these fields as doubles instead of decimals?
I am using a Microsoft SQL Server database. My column type is decimal(38, 2). The value that's stored there is ~ 1.0005e+35. I know that this value is too big to fit into a C# Decimal
so I need to fit it into a System.Double
instead.
Upvotes: 1
Views: 1242
Reputation: 1842
I figured it out. Apparently EF Core designates the different SQL types directly to C# types. So a SQL decimal
maps to a C# Decimal
. A SQL float
maps to a C# System.Double
. And a SQL real
maps to a C# System.Float
.
So the solution to my issue was to change the decimal(38,2)
to a float
in my SQL table
Upvotes: 2