This is a migrated thread and some comments may be shown as answers.

Parameter value '<decimal>' is out of range

2 Answers 1323 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gary
Top achievements
Rank 1
Gary asked on 27 Oct 2015, 07:21 PM

I am completely confused and have lost the better part of my day to this issue. 

I have some fields in my database table defined as ... 

 

[SheetWidth]            DECIMAL(6,2) NULL,
[SheetHeight]           DECIMAL(6,2) NULL,
[SheetThickness]        DECIMAL(6,2) NULL,

They are associated with the following properties on a model ... 

 

public Decimal? SheetWidth { get; set; }
 
public Decimal? SheetHeight { get; set; }
 
public Decimal? SheetThickness { get; set; }

 They are mapped in the metadatasource ... 

 

map.HasProperty(e => e.SheetWidth)
    .HasColumnType("decimal")
    .HasScale(6)
    .HasPrecision(2)
    .IsNullable();
 
map.HasProperty(e => e.SheetHeight)
    .HasColumnType("decimal")
    .HasScale(6)
    .HasPrecision(2)
    .IsNullable();
 
map.HasProperty(e => e.SheetThickness)
    .HasColumnType("decimal")
    .HasScale(6)
    .HasPrecision(2)
    .IsNullable();

 

 I am attempting to create a new record from a call to a WebAPI service by passing in the following JSON (which maps to the model) ... 

 

{
    "SheetWidth": 6.5,
    "SheetHeight": 8.5,
    "SheetThickness": null,
}

 Everything seems to go fine until the SaveChanges() method is called and I get the following response back ... 

 

 "Insert of '594112938-24' failed: System.ArgumentException: Parameter value '8.​500000' is out of range"

 

I understand why I am getting the error ... clearly 8.500000 ... is out of the (6, 2) scale/precision range that I had specified ... the question I have is WHY is 8.5 being converted into 8.500000. While in debug mode I observed the value of the all the way to the "SaveChanges()" method and it remained 8.5. Based on the data types I assigned I would have expected it to be saved as ... 8.50 ... which is exactly the behavior I want. 

 

So what's going on inside "SaveChanges()" that killing my datatype? And what can I do about it?

 

 

 

 

 

 

 

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Ady
Telerik team
answered on 30 Oct 2015, 09:41 AM
Hi Gary,

 It seems you have got the Fluent mapping wrong. It should be 'HasPrecision(6).HasScale(2)' and not the other way round.
Can you fix this and check if you still get the error?

Regards,
Ady
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
Gary
Top achievements
Rank 1
answered on 02 Nov 2015, 07:36 PM
FOR SHAME ON ME!! You were correct! I completely had them backwards. DOH!
Tags
Data Access Free Edition
Asked by
Gary
Top achievements
Rank 1
Answers by
Ady
Telerik team
Gary
Top achievements
Rank 1
Share this question
or