Code First: Avoid discriminator column and keep inheritance

天大地大妈咪最大 提交于 2020-02-11 18:53:49

问题


In my project I have:

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

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

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

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.

Is it possible?


回答1:


A couple options:

  • Make BaseEntity abstract
  • Use modelBuilder.Ignore<BaseEntity>() in yourDbContext.OnModelCreating


来源:https://stackoverflow.com/questions/30893785/code-first-avoid-discriminator-column-and-keep-inheritance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!