我有这个类:
public class PayTerm
{
public int PayTermExternalKey { get; set; }
public int Code { get; set; }
public string Name { get; set; }
}
在数据库中,PayTermExternalKey
是smallint
,因为它与另一个系统表smallint
的键有关,在我的程序中有一个网格,我在其中保存 PayTerm
类的实例...除了正确但是当我去恢复 PayTerm
列表时我在 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'.
我查看了所有使用该属性的类,结果发现它总是 int ...
更新
我创建的表很糟糕,现在 PayTermExternalKey
是正确的类型,现在错误不再发生。
最佳答案
我不太了解,但我认为您应该将 PayTerm 类中 PayTermExternalKey 的类型从 int 更改为 short。因为 System.Int16 是 short 类型。
关于c# - Entity Framework 错误...属性无法设置为 'System.Int16' 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55490573/