Entity Framework adds redundant duplicate discriminator column to table

c# ef-fluent-api entity-framework entity-framework-6 table-per-hierarchy

Accepted Answer

Any use of EF6 inheritance requires extreme caution. Even if a class is not used, referenced, or specified anywhere inside the EF model, EF utilises reflection to identify any classes within the same assembly that either directly or indirectly inherit some of the entities that are a part of EF inheritance.

Adding one more class (in your example, it would be calledEquity )

public Asset2 : Asset { }

is sufficient to introduce the normDiscriminator due to the fact that it is not set up to utilise the discriminator column for theBond class.

This behaviour, which was altered in EF Core so that only the explicitly specified derived classes are taken into account, is the cause of unexpected errors like the one you experienced.

Either indicate these classes with in EF6.NotMapped usage, attributeIgnore effectively map them as entities using a fluent API.

3
9/9/2017 12:59:56 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow