小编Dus*_*258的帖子

实体框架代码优先 - 将smallint和整数转换为int32

我正在为数据库工作一个小型服务工具.我的问题是,由于上次更新,一些smallint-colums必须更改为整数.

public class TEST
{
    public int ID { get; set; }
    //public Int16 ID { get; set; }
    public string TEST { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

我将类型从Int16更改为int.一切正常,除了我不能再使用旧版本的数据库了.Exception类似于"System.Int32 expect,found Typ System.Int16".

有没有办法将所有smallint和整数转换为int32?

有任何想法吗?我的环境:EntityFramework 5.0.0 .NET 4.5 FirebirdClient 3.0.2.0

我试图在模型制作者中强制演员:

        modelBuilder.Entity<TEST>()
        .Property(p => p.ID)
        .HasColumnType("smallint");
Run Code Online (Sandbox Code Playgroud)

例外:

错误2019:指定的成员映射无效.Typ'ContextRepository.TEST'中成员'ID'的类型'Edm.Int32 [Nullable = False,DefaultValue =]'与成员'FirebirdClient.smallint [Nullable = False,DefaultValue =,StoreGeneratedPattern = Identity]'不兼容"CodeFirstDatabaseSchema.BUNDLAND"类型中的"SCHLUESSEL"

使ID Int16然后将所有内容转换为smallint(HasColumnType("int"))工作正常,但会给出异常,数字大于31767(最小smallint)...

c# firebird entity-framework ef-code-first

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

ef-code-first ×1

entity-framework ×1

firebird ×1