Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 593
Adi Avatar asked Jun 17 '15 13:06

Adi


1 Answers

A couple options:

  • Make BaseEntity abstract
  • Use modelBuilder.Ignore<BaseEntity>() in yourDbContext.OnModelCreating
like image 152
jjj Avatar answered Oct 09 '22 10:10

jjj