Entity framework 错误...属性 无法设置为 'System.Int16' 值

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

我有这个Class:

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

在数据库中,PayTermExternalKeysmallint 因为它与另一个系统 table 的键相关,即 smallint,在我的程序中我有一个网格我在哪里保存 PayTerm class 的实例...除了正确但是当我去恢复 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'.

我查看了所有使用 属性 的 classes,结果发现它总是 int ...

更新 我创建的 table 很糟糕,现在 PayTermExternalKey 是正确的类型,现在错误不再发生。

我不太了解,但我认为您应该将 class PayTerm 中 PayTermExternalKey 的类型从 int 更改为 short。因为System.Int16是short类型。