5.7.441 build with the DBContext template and potentially other templates as well.
Precision and scale are not explicitly set for decimal types in the model configuration. Decimal types default to (18, 2) when not explicitly specified which causes values to be rounded down.
Precision and Scale
Re: Precision and Scale
Please give us the following information:
1) you are using the Database-First approach (generating model basing on a predefined database), aren't you?
2) have you tried to customize the Database-First mapping via Visual Studio > Tools > Entity Developer > Options > Server Options > SQL Server? Be aware that the new mapping is applied only for the newly created models (or if you will recreate the entities in CSDL basing on SSDL in an existing model). If this doesn't help, please specify the exact steps we should follow in our environment to reproduce the issue.
1) you are using the Database-First approach (generating model basing on a predefined database), aren't you?
2) have you tried to customize the Database-First mapping via Visual Studio > Tools > Entity Developer > Options > Server Options > SQL Server? Be aware that the new mapping is applied only for the newly created models (or if you will recreate the entities in CSDL basing on SSDL in an existing model). If this doesn't help, please specify the exact steps we should follow in our environment to reproduce the issue.
-
- Posts: 21
- Joined: Tue 07 Jan 2014 12:38
Re: Precision and Scale
1) Database-first - yes
2) Customized options - no
To reproduce:
1) Create a table with a column of type decimal - any precision and any scale you wish.
2) Create a new model in Entity Developer based on this new table with the DbContext template.
3) Generate the code.
Result: There is no explicit call to .HasPrecision() for any columns of type decimal. The Entity Framework defaults decimal types to (18, 2) when HasPrecision is not specified which obviously causes data to be rounded and lossed during insertion if your column's precision/scale are defined differently.
This:
Should be this:
Here is the template code that needs to be added:
2) Customized options - no
To reproduce:
1) Create a table with a column of type decimal - any precision and any scale you wish.
2) Create a new model in Entity Developer based on this new table with the DbContext template.
3) Generate the code.
Result: There is no explicit call to .HasPrecision() for any columns of type decimal. The Entity Framework defaults decimal types to (18, 2) when HasPrecision is not specified which obviously causes data to be rounded and lossed during insertion if your column's precision/scale are defined differently.
This:
Code: Select all
modelBuilder.Entity<Order>()
.Property(p => p.SubtotalIncludingTax)
.IsRequired()
.HasColumnType("decimal");
Code: Select all
modelBuilder.Entity<Order>()
.Property(p => p.SubtotalIncludingTax)
.IsRequired()
.HasColumnType("decimal")
.HasPrecision(18, 4);
Code: Select all
if (propertyDataType == EntityDataType.Decimal) {
#>
.HasPrecision(<#= prop.Precision #>, <#= prop.Scale #>)<#+
}
Re: Precision and Scale
Thank you for the detailed description. We will notify you when the issue is fixed in a predefined DbContext template.
Re: Precision and Scale
The bug with generating .HasPrecision for decimal types when using non-attribute fluent mapping (DbContext template) is fixed in the new (5.7.451) build of Entity Developer.
It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=32&t=30472.
It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=32&t=30472.