Code First: Avoid Discriminator Column and Preserve 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 tables in my database:

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

      

Of course, since it MyTable

inherits from BaseEntity

, I get this Discriminator field . I want to get rid of the field Discriminator

since I don't need the created table BaseEntity

and I don't need to implement some kind of inheritance in my database.

Is it possible?

+3


source to share


1 answer


A couple of options:



  • Make BaseEntity

    abstract

  • Use modelBuilder.Ignore<BaseEntity>()

    inyourDbContext.OnModelCreating

+10


source







All Articles