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
Dangerous decimal fractional digit truncation when changing from EF core 3 to EF 5 on MS-SQL Server #23681
Comments
This is a breaking change that we be documenting shortly. See dotnet/EntityFramework.Docs#2923. |
But if this is not a bug it would be a major breaking change. It will produce much harm in production environments without throwing an error. |
@bennil This is a breaking change. The default has not changed--it has always been 18, 2. However, if your database column is set up with something different from the default, and you don't tell EF this in the mappings, then EF would previously send the full value and let the database sort it out. Now the default is respected on the EF and SqlClient sides as well, so if you have your model configured differently from the database you will experience this breaking change. You can get back to the old behavior by making sure the types are fully specified in the EF model. (Note that in previous versions there was already a warning when using a decimal column without an explicit type mapping.) |
@ajcvickers Thanks for the explanation. In my case I don't use the ef tooling to gernerate my database. So I was not aware of that warning. |
@bennil The warning is generated in runtime logs. It is not related to the EF tooling. |
OK never paid attention to these logs :-( But I still see it as default change for all who did not initially create their database with EF tooling. |
Today I faced a dangerous production problem after upgrading form .net 3.1 (Microsoft.EntityFrameworkCore.SqlServer 3.1.8) to .net 5 (Microsoft.EntityFrameworkCore.SqlServer 5.0.1).
Table decimal values are truncated to only two fractional digits!
I could reproduce the changed behavior in a short sample project:
.net 5 output:
Expected 5.1234567; Received Value 1: 5.1200000
Expected 5.1234567891; Received Value 2: 5.1200000000
Expected 5.12345; Received Value 3: 5.12000
With .net core 3.1 the decimal fractional digits are not truncated and work as expected.
Sample reproduce project
EfCore5InvalidDecimalPrecisionTest.zip
EfCorePrecisionTest.Common/CreateDecimalTestDb.sql
Affected Database Table Column Types
Version Info
Tested with Microsoft SQL Server Express (64-bit) 14.0.3048.4 on Ubuntu (16.04) (Docker)
The text was updated successfully, but these errors were encountered: