代码优先:避免鉴别器列并保持继承

Code First: Avoid discriminator column and keep inheritance

在我的项目中我有:

public class BaseEntity {
    [Key]
    public int Id {get; set; }
}

然后我必须定义 10+ POCO 类 来定义我数据库中的 tables:

public class MyTable : BaseEntity {
    //define properties here
}

当然,因为 MyTable 继承自 BaseEntity 我得到了那个 Discriminator 字段。我想摆脱 Discriminator 字段,因为我不需要创建 table BaseEntity 也不需要在我的数据库中实现某种继承。

可能吗?

几个选项:

  • 制作BaseEntityabstract
  • yourDbContext.OnModelCreating
  • 中使用modelBuilder.Ignore<BaseEntity>()