Reputation: 23
I have a problem with saving a decimal in EntityFramework (Model First). In my EDMX I declared my proprierty as a Decimal(30,10) then I tried to save the number: '1215867935736100000'
The result is:
Parameter value '1215867935736100000' is out of range.
I tried to make an INSERT query with SQL Server 2008 R2 Management Studio
INSERT INTO MyTable (MyColumn) VALUES (1215867935736100000)
and the record is saved correctly.
Do you have any idea?
Thanks, Max
Upvotes: 2
Views: 6891
Reputation: 14580
This could be an issue with the version of EF that you are using.
I have a code first version of the problem and can almost reproduce the error you are getting. The error I get includes a .00 in the message
{"Parameter value '1215867935736100000.00' is out of range."}
The way I solved it was to add .HasPrecision(30,10)
to the EntityTypeConfiguration
class.
this.Property(t => t.value)
.HasColumnName("value")
.HasPrecision(30,10) //this line resolves the problem in my test code
.IsRequired();
This doesn't fix your problem but I can at least confirm it is possible for Entity Framework to write the value 1215867935736100000
to the database.
CREATE TABLE [dbo].[TestTable1](
[id] [int] IDENTITY(1,1) NOT NULL,
[value] [decimal](30, 10) NOT NULL
) ON [PRIMARY]
The test code:
MyContext testTableContext = new MyContext();
TestTable1 testTable1 = new TestTable1();
testTable1.value = 1215867935736100000;
testTableContext.TestTable1.Add(testTable1);
testTableContext.SaveChanges();
Upvotes: 2