EF6 - Invalid cast from decimal to int32

c# entity-framework entity-framework-6

Question

I have a table with a field defined in the following way:

...
[oneField] NUMERIC(2) NULL,
...

And the related C# entity model

...
public int? oneField { get; set; }
...

Fluent arrangement...

Property(r => r.oneField)
    .HasColumnName("oneField");

With all of the aforementioned in mind, when I try to get data from the database, I receive the following error.

System.InvalidOperationException: The specified cast from a materialized
  'System.Decimal' type to a nullable 'System.Int32' type is not valid.

Any suggestions for resolving this? I could see how if the NUMERIC field had a decimal portion, that may be problematic, but since the value is only an integer with two digits, why can't it be converted into an INT32?

I am aware that the issue will be resolved if I alter the column in the table to be an INT, but I prefer to maintain the NUMERIC(2) since it more accurately depicts the data that would be kept there (Numbers with 2 digits).

1
1
5/31/2018 9:12:12 AM

Accepted Answer

ZZZ_tmp
4
5/31/2018 9:30:20 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow