Skip to content

Improvement - Not truncating/rounding decimals for SqlParameter with Scale = 0, and throws Out of Range Exception #1214

@julian-gargicevich

Description

@julian-gargicevich

After upgrading from 3.1 to 5 my decimal types started throwing an Out of Range Exception on save. I know there's a breaking change related, but even after setting the precision using the new API I'm still getting this error.

My previous configuration was working in 3.1:

builder.Property(e => e.BookValuePerSqmtr).HasColumnType("decimal(14,0)");

Trying to save this number 22351.969005269646026090843821 throws the out of Range exception, while it was doing the right rounding/truncating in 3.1.

builder.Property(e => e.BookValuePerSqmtr).HasPrecision(14,0);

I tried changing the model builder configuration to use the new HasPrecision method but I'm still getting the same error. Is there any way to re enable the rounding before saving?

Microsoft.EntityFrameworkCore.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.'
ArgumentException: Parameter value '22351.969005269646026090843821' is out of range.

EF Core version: 5.0.7
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement 💡Issues that are feature requests for the drivers we maintain.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions