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?