According to this source
http://weblogs.asp.net/manavi/archive/2010/12/24/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph.aspx
it should be possible to have the TPH discriminator column be an integer:
Also, changing the data type of discriminator column is interesting. In the above code, we passed strings to HasValue method but this method has been defined to accepts a type of object:
public void HasValue(object value);
Therefore, if for example we pass a value of type int to it then Code First not only use our desired values (i.e. 1 & 2) in the discriminator column but also changes the column type to be (INT, NOT NULL):
modelBuilder.Entity() .Map(m => m.Requires("BillingDetailType").HasValue(1)) .Map(m => m.Requires("BillingDetailType").HasValue(2));
However, when I do that in my code I see discriminator values like "1" and "2", but the column type is still
nvarchar(128), not null
Is it in fact possible to specify an integer discriminator column? If so, how?
I'm certain that I specify my mapping as .HasValue(1) and not .HasValue("1").
modelBuilder.Entity<X>()
.Map<X>(m => { m.Requires("BillingDetailType").HasValue(0).HasColumnType("tinyint"); })
.Map<Y>(m => { m.Requires("BillingDetailType").HasValue(1); m.MapInheritedProperties(); })
.Map<Z>(m => { m.Requires("BillingDetailType").HasValue(2); m.MapInheritedProperties(); })
;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With