I am using code-first method to generate my DB. In one of the cases, there is an inheritance hierarchy which gets correctly mapped to a TPH scenario. However, the Discriminator column which gets created (automatically) isn't available in the base C# class.
I want the base class to have that Discriminator property, but if I add a property with that name, the DB which gets generated after update-database, has a column called Discriminator1.
I've tried -
modelBuilder.Entity<BaseClass>()
.Map<DerivedClass1>(m => m.Requires("Discriminator").HasValue("DerivedClass1").IsRequired())
.Map<DerivedClass2>(m => m.Requires("Discriminator").HasValue("DerivedClass2").IsRequired())
.Map<DerivedClass3>(m => m.Requires("Discriminator").HasValue("DerivedClass3").IsRequired());
But then, when I am trying to enter seed data, I get this error -
System.Data.Entity.Core.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---> System.Data.Entity.Core.MappingException: (526,10) : error 3032: Problem in mapping fragments starting at line 526:Condition member 'BaseClass.Discriminator' with a condition other than 'IsNull=False' is mapped. Either remove the condition on BaseClass.Discriminator or remove it from the mapping.
So all I want is to see the Discriminator property in C# class, without using any extra column (whose value I want to read after fetching a row from DB).
Thanks for any help.