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
Problem mapping decimal to numeric(9, 0) in EF Core 5.0 #2923
Comments
Notes for triage: In 5.0, we started setting the precision on parameters for decimal type mappings. This causes SqlClient to throw. Query from 3.1:
Query from 5.0:
|
Notes from triage: Always encrypted means that we can no longer avoid setting parameter facets in cases like this. Unfortunately, this causes SqlClient to throw in some cases where it previously would not. We will document this as a breaking change in EF Core 5.0. @cheenamalhotra @David-Engel Do you have any thoughts about whether or not the underlying SqlClient behavior is correct? Specifically, should it be throwing for the "999000169.0" value? |
cc @karinazhou |
Hi, According to SQL Server docs, the precision
"999000169.0" will fail as expected for Thanks, |
Moving to the docs repo to document this as a breaking change. |
Based on Karina's comment above, it looks like precision set here is incorrect. SqlClient cannot change it, and server will fail. |
File a bug
Context
We use EF Core database first, so our model is reverse engineerd using
dotnet ef dbcontext scaffold
.This maps our numeric fields of type
numeric(9, 0)
to C#decimal
s.This has always worked in EF Core until EF Core 5.
Problem
When trying to create or update an entity where the value is the max length of 9, the action fails.
I have found that adding or leaving out the decimal place has influence on this behaviour.
For example:
This makes me believe only the precision of the decimal gets checked without checking the decimals.
In my 3 examples only the first one has a precision of 10 where the other ones both have a precision of 9.
I believe this is a bug in EF Core 5 as the last example proves that the actual presence of the
.0
has no effecton whether the value can be inserted. Ignoring the
.0
our value999000169.0
also ends with a precision of 9and should be able to get inserted.
Further, this has worked in EF Core up to 3.1 and I can not find anything in the EF Core 5 changelog
regarding breaking changes around this topic.
Example
In my example I have the same small project using EF Core 3.1 to show the working version
and 5.0 to show the exception.
Stacktrace
Provider and version information
EF Core version: 5.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.8.2
InsertTest.zip
The text was updated successfully, but these errors were encountered: