Usman Usman - 3 months ago 51
C# Question

How can 'discriminator' column be avoidable in Code First Entity Framework

How can I avoid creating a column as "Discriminator" inside the database , If I inherit my business class from model class ( model class is mapped on database table).

Because, at the moment, if I inherit my business class ( e.g Specifics) to an existing model class ( i.e DataSpecific ), It asks for code first migration. In the migration, I can see discriminator as new column. I really don't want this. Because, original model class is being used in the whole application and that code works fine.

How can I stop the creation of "descriminator" column

C# Code :

Model Class

public class DataSpecific


Busines Class

public class Specific


as a result I can see following code in the migration

AddColumn("dbo.Consignments", "Discriminator", c => c.String(nullable: false, maxLength: 128));

How can I avoid this?


Either apply NotMapped Data Annotation to your business class:

public class Specific : DataSpecific

or use Ignore Fluent API: