Code First: Avoid discriminator column and keep inheritance

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

Question

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
5
5/23/2017 10:30:56 AM

Accepted Answer

A couple options:

  • Make BaseEntity abstract
  • Use modelBuilder.Ignore<BaseEntity>() in yourDbContext.OnModelCreating
11
6/24/2015 11:30:11 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow