Entity framework error ... property could not be set to 'System.Int16' value

c# entity-framework-6

Question

I have this Class:

public class PayTerm
{
    public int PayTermExternalKey { get; set; }
    public int Code { get; set; }
    public string Name { get; set; }
}

In the Database, PayTermExternalKey is smallint because it is related to the key of another system table which is smallint, in my program I have a grid where I save instances of the PayTerm class ... except correctly but when I go to recover the PayTerm list I have an error in EntiyFramework

The 'PayTermExternalKey' property on 'PayTerm' could not be set to 'System.Int16' value. You must set this property to a non-null value of type 'System.Int32'.

I looked in all the classes where I use the property and it turns out to be always int ...

UPDATE I had created the table badly, now PayTermExternalKey is the right type, now the error no longer occurs.

1
1
4/3/2019 9:25:18 AM

Accepted Answer

I don't understand much but I think you should change PayTermExternalKey's type in class PayTerm from int to short. Because System.Int16 is short type.

0
4/3/2019 8:50:24 AM


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