代码优先:避免鉴别器列并保持继承 [英] Code First: Avoid discriminator column and keep inheritance

查看:18
本文介绍了代码优先:避免鉴别器列并保持继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我有:

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

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

Then I have to define 10+ POCO classes to define the tables in my database:

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

当然,因为 MyTable 继承自 BaseEntity 我明白了 鉴别器字段.我想摆脱 Discriminator 字段,因为我不需要创建表 BaseEntity 也不需要在我的数据库中实现某种继承.

Of course, because MyTable inherits from BaseEntity I get that Discriminator field. I want to get rid of the Discriminator field as I do not need the table BaseEntity to be created nor I need to implement some sort of inheritance into my database.

有可能吗?

推荐答案

几个选项:

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

这篇关于代码优先:避免鉴别器列并保持继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆