I have a model hierarchy configuration like so:
[Table("A")]
abstract class A { }
class B : A { } // treated as abstract
[Table("C")]
class C : B { }
This results in a TPH for A and B, and a TPT for C. So far this seems to work fine. There are two database tables being generated: "A" which contains both A and B model records, and "C" which contains only C model record columns not already kept in table "A".
For the TPH arrangement on Table A, there is a generated "Discriminator" column, which EF CF creates on its own to distinguish type A vs type B. This column is fine and expected; however, I would like to rename it. For this post's sake, the new name might be "Type".
The tutorials that document how to do this appear to suggest this:
modelBuilder.Entity<A>()
.Map<B>(m=>m.Requires("Type").HasValue(typeof(B).Name))
.Map<C>(m=>m.Requires("Type").HasValue(typeof(C).Name));
This does not seem to work, though, as I get a runtime error during database generation saying that the models of types A, B, and C are being added to the same table, and, "Mapping conditions can be used to distinguish the rows that these types are mapped to." (Whatever this means.)
I also tried:
modelBuilder.Entity<A>()
.Map<B>(m=>m.Requires("Type"))
.Map<C>(m=>m.Requires("Type"));
.. as well as ..
modelBuilder.Entity<A>().Map(m=>m.Requires("Type"));
.. and even though these attempts compile and produce no runtime errors, there seems to be no effect, as the Discriminator column remains as "Discriminator".
I tried to create a new string property on A called "Discriminator", to which I was going to subsequently rename the property's column metadata, but that just gave me two "Discriminator" columns: "Discriminator" and "Discriminator1".
Ideas?