c# - 代码优先 : Avoid discriminator column and keep inheritance

标签 c# ef-code-first entity-framework-6

在我的项目中我有:

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

然后我必须定义 10 多个 POCO 类来定义我的数据库中的表:

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

当然,因为 MyTable 继承自 BaseEntity 我得到了 Discriminator field 。我想去掉 Discriminator 字段,因为我不需要创建表 BaseEntity,也不需要在我的数据库中实现某种继承。

这可能吗?

最佳答案

几个选项:

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

关于c# - 代码优先 : Avoid discriminator column and keep inheritance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30893785/

相关文章:

c# - Entity Framework 5 代码优先不创建数据库

entity-framework - EF Code First 现有数据库

c# - EF - 如果使用实体对象,则重新插入外键

c# - DataAccessLayer 和组织解决方案

c# - 支持使用 C# 中的 AT 命令发送和接收 SMS 的离线/桌面应用程序

c# - 根据 ComboBox 选择更改 GroupBox 的内容

c# - 是否有支持混合 C++ 和 C# 应用程序的崩溃报告服务?

c# - 我无法从类调用我的方法来形成

c# - 通过导航属性访问外键 ID 属性时如何避免延迟加载?

c# - Entity Framework 按时间过滤数据