Question:
I'm trying to generate migrations using the command:
dotnet ef migrations add InitialMigration --context MyContext
and the same is returning me the following message.
System.InvalidOperationException: The entity type 'Individual' is part of the hierarchy, but does not have a discriminator value configured.
In my classes I have PessoaFisica
and PessoaJuridica
inheriting from Pessoa
and Funcionario
inheriting from PessoaFisica
( public class Funcionario : PessoaFisica
).
modelBuilder.Entity<Funcionario>()
.ToTable("Funcionario");
Answer:
What is happening, it seems to me, is that when using the TPH(Table Per Hierarchy) method you have to mention the value of the discrimination column. ex:
https://blogs.msdn.microsoft.com/alexj/2009/04/14/tip-12-how-to-choose-an-inheritance-strategy/
For that, in the model builder, you have to do something similar like:
modelBuilder.Entity<Funcionario>()
.Map<Funcionario>(m => m.Requires("Descriminator").HasValue("FUNC"))