Skip to content

A declaration on a concrete TPC root reaches the root's table only: the derived tables get no constraint, in silence #101

Closed

Description

@CaffeinatedCoder

Found by the pre-preview sweep of main @ 948496a (GPT's read of the planner; reproduced in a scratch test).

What happens

Reservation is the concrete root of a TPC hierarchy, with Stay and Hold in tables of their own. DeclarePostgres on Reservation gives:

CREATE EXTENSION IF NOT EXISTS btree_gist;
ALTER TABLE reservations ADD CONSTRAINT ex_res EXCLUDE USING gist ("RoomId" WITH =, "Period" WITH &&);

Nothing for stays and holds, and no error. Overlapping rows in either derived table are accepted. EF Core gives an index declared on a TPC root to every table of the hierarchy, and 5.x gave each table its copy of an exclusion constraint, so a consumer expects the same here.

An abstract root is refused today ("is not mapped to a table. The declaration would produce nothing, without an error."). The 5.x reader refuses a TPC root with derived types too (ComplexIndexes5xExclusionReader.cs:54). A declaration written here on a concrete root is the one case that passes.

Scenario

public sealed class Declared : ITestModel
{
    public static void Build(ModelBuilder b)
    {
        var pg = PgSchema.For<TpcReservation>();
        b.Entity<TpcReservation>().UseTpcMappingStrategy().ToTable("reservations")
            .DeclarePostgres(_ => [pg.Exclusion(pg.Equal(x => x.RoomId).Overlaps(x => x.Period), name: "ex_res")]);
        b.Entity<TpcStay>().ToTable("stays");
        b.Entity<TpcHold>().ToTable("holds");
    }
}
// Contexts.Diff<Bare, Declared>().Shape(): the two statements above, both for "reservations".

Change

Until the resolver has TPC (#43: the tables a declaration lands on, each copy resolved against its table's entity type), refuse a declaration on an entity type that is mapped with TPC and has derived types, where the migration leads, naming #43's limit. A declaration on a leaf type stays allowed: its table is its own.

Test

The model above refused in PgExclusionMigrationTests, a leaf declaration accepted, and the guard shown to fail without the check.

Activity

  1. added this to the 11.0.0 milestone on Nov 14, 2026
  2. added
    bug
    silent
    severity/high
    package/core
    package/postgresql
    area/constraints
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/constraintsbugpackage/corepackage/postgresqlseverity/highsilent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions