Discriminator columns are created in Snapshot for wrongly configured TPC mapping strategy #33605
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
regression
type-bug
Milestone
Bug explanation
Assume the following sample:
By convention, EF tools would create the following tables for the abovementioned hierarchy: Animals, Cats, Dogs, and Foods, meaning table-per-hierarchy (TPH).
If I want to create the tables as table-per-concrete-type (TPC), I can explicitly ignore the abstract class with the following line
modelBuilder.Ignore<Animal>();
When creating the first migration with the Ignore call via
dotnet ef migrations add Initial
, EF is confused about mixing TPH and TPC by adding a Discriminator value in the Snapshot file for the concrete classes which looks like thisWhen a second migration is created, the discriminator is dropped.
After calling
dotnet ef database update
, an exception is thrown because the discriminator column does not exist.Reproduction steps
dotnet ef migrations add Initial
dotnet ef migrations add Second
dotnet ef database update
Seems to address a maybe similar problem like #20410
Include provider and version information
EF Core version: 8.0.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: MacOS Sonoma 14.2.1
IDE: JetBrains Rider 2024.1
EfCoreInheritanceSample.zip
The text was updated successfully, but these errors were encountered: