简体   繁体   中英

Code First: Avoid discriminator column and keep inheritance

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?

A couple options:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM