EntityFramework: Parameter value out of range.

I have a problem storing decimal number in EntityFramework (first model). In my EDMX I declared my proprierty as decimal (30,10) then I tried to store the number: '1215867935736100000'

Result:

Parameter value '1215867935736100000' is out of range.

      

I tried to make an INSERT query using SQL Server 2008 R2 Management Studio

INSERT INTO MyTable (MyColumn) VALUES (1215867935736100000)

      

and the record is saved correctly.

Do you have any ideas?

Thanks Max

+2


source to share


1 answer


This could be a problem with the EF version you are using.

I have the first version of the problem, and you can almost reproduce the error you are getting. The error I am getting contains .00 in the message

{"The value of the parameter '1215867935736100000.00' is out of range." }

As I decided, add this to .HasPrecision(30,10)

the class EntityTypeConfiguration

.

this.Property(t => t.value)
    .HasColumnName("value")
    .HasPrecision(30,10) //this line resolves the problem in my test code
    .IsRequired();

      



It doesn't fix your problem, but I can at least confirm that the Entity Framework can 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]

      

Security Code:

MyContext testTableContext = new MyContext();
TestTable1 testTable1 = new TestTable1();
testTable1.value = 1215867935736100000;
testTableContext.TestTable1.Add(testTable1);
testTableContext.SaveChanges();

      

0


source







All Articles