c# - Entity Framework 错误...属性无法设置为 'System.Int16' 值

标签 c# entity-framework-6

我有这个类:

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

在数据库中,PayTermExternalKeysmallint,因为它与另一个系统表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/

相关文章:

c# - 基于字典比较两个对象的相等性

c# - Azure RelayManagementClient 的 ManagedIdentityCredential

c# - 如何使用 Sql Server 解决 EF 6 中不受支持的 DateTimeOffsets 问题?

entity-framework - 在 EF6 中存储复杂的分离对象图

c# - 查找直到引用正则表达式

C# OnCommand 调用警告框

c# - 使用 Entity Framework Code First 将 SQL 表主键定义为区分大小写

c# - 如何在 Entity Framework 6 中混合使用 TPH 和 TPT?

c# - 如何确保 Autofac 在 EF6 DbContext 上调用 Dispose()

c# - 没有重复的偶数和奇数随机数