Skip to content

One landing function: the tables a declaration lands on, total over the mapping strategies #118

Done

Description

@CaffeinatedCoder

2026-11-25: built in three slices. #187 (PR #188, merged): a declaration on a TPC type lands on every table of the hierarchy below it, with 5.x's names for the copies. #189 (PR #190, merged): the 5.x reader reads a constraint on a TPC type from 5.5.0 on, and the fixture has the hierarchy. #191 (PR #192, open): a split entity, and the refusal of a derived TPT type's inherited column by name. What stays open is #85, the derived type's column named from the base type. This issue closes when PR #192 is in.

Two deviations from the proposal below, both on #187 and #191: a copy is resolved against the declaring entity type with the copy's table, and the compiled snapshot is held by the planner's tests, not by SchemaResolverTests.


Decided 2026-11-25 by the maintainer: the proposal below, as written. A copy's name that is too long is refused; 5.x's shortening is ported only if a real model needs it. Built in three slices, each a sub-issue of #111.


Proposal, 2026-11-25. Each sentence that says "measured" was read from EF Core 11.0.0 with Npgsql 11.0.0 in a scratch project outside the repository, on a configured model and from the snapshot's generated code; a compiled snapshot was not run. Everything else is a recommendation. What 5.x did is read from its source (DeclarationTables, CopyName, ThrowIfMissingFromDerivedTable).

What is settled already

Measured

Strategy What the model says
TPC, concrete root The root has its table and each derived type its own. The root's property answers GetColumnName for every one of those tables, also where a derived table renames nothing. A property of a complex property answers a name for the derived tables too; whether the relational table has that column there was not measured (5.x found on EF Core 10 that it does not)
TPC, abstract root The root has no table; GetDerivedTypesInclusive() gives the derived types with theirs
TPH Every type answers the one table. A derived type's property has a column there
TPT A derived type's own table has no column for an inherited property (GetColumnName is null); the base table has it
Entity splitting The type's table is the first one; a property of the second fragment has no column there (null), and GetMappingFragments() names the fragment
Table splitting Both types answer the shared table, and each one's property has its column there

The snapshot's code records what the function reads: ToTable, UseTpcMappingStrategy(), HasBaseType, SplitToTable.

Proposed

1. One function, Landings(entityType), in the kernel, used on both sides of a diff. It returns the tables a declaration on that type lands on, each with the entity type to resolve against, or refuses:

Declared on Lands on
a type with a table of its own, no TPC below it that table (as today)
a TPC type its own table if it has one, and the table of every type derived from it that has one. One object per table
an abstract TPC root the derived types' tables. Today this is refused as "not mapped to a table"
a derived type that shares its table (TPH) refused, as today (#82)
a derived TPT type, reading an inherited column refused, naming the base type: the column is in the base type's table, and an object there holds among every type's rows
a split entity, every column it reads in one fragment that fragment's table
a split entity, columns in more than one fragment refused
a split entity, SQL written by hand and no column by a path refused: nothing says which table the SQL means
a type that shares its table with another type that is no base of it (table splitting) the table (as today): the rows are the same rows
a type with no table and no TPC below it refused, as today

A copy whose table has no column for a path the declaration reads is refused, with the table named, as 5.x did.

2. The copies' names follow 5.x. A default name has the table in it, so each copy has its own. With an explicit name the declaring type's own table keeps it, and a derived table's copy is {name}_{table} when the name is taken in the schema, and the name itself when it is taken within the table. Which of the two it is, the contributor's claims say already (Claims). The rule lives in the resolver, so no contributor writes it.

3. The stored form does not change. One declaration is one annotation on the type it was written on. The copies are made when a model is read for a diff, on both sides, so a derived type added later gets its copy by the next migration, and one removed loses it.

4. The contract does not change. A contributor's Resolve is called once per landing with a resolver for that table.

5. The 5.x reader's refusal of a TPC root goes for a snapshot of rendering version 3 or later (5.5.0 and later), where 5.x made the copies. An older snapshot's constraint is on the root's table alone; I would keep refusing that one, with the message that says to scaffold once with 5.6 first. The fixture gains a TPC hierarchy; regenerating it needs the network and the .NET 10 runtime.

Two questions for the maintainer

  • A copy's name that is too long. 5.x shortened a name it made up for a copy (ShortenConstraintCopyNames, with ~ and a rule that depends on the other names of the scope). Here a name that is too long is refused. Either port 5.x's shortening for copies, so that every 5.x TPC model hands over with no operations, or refuse such a copy and say in the guide that the model needs a shorter name before it moves. I recommend refusing first and porting only if a real model needs it: the shortening is the one part of 5.x's rule that depends on what else the schema holds.
  • The slices. I would build three: the function with TPC and the names in the kernel, held by SchemaResolverTests on a model and its compiled snapshot and by a live test on PostgreSQL; then the 5.x reader with the fixture; then entity splitting. An object on a column only a derived type has cannot be declared while the type shares its table #85's path is a fourth, on its own issue.

Before preview.2. From the architecture debate of 2026-11-14; not decided. Belongs with #43's TPC item and #85.

Problem

A declaration is resolved against the one table of the entity type it is written on. Each mapping strategy that does not fit has been one finding: a derived type of a shared table (#82, refused, and its cost #85), a concrete TPC root (#101, the derived tables get nothing), an entity split over two tables (read: a column of the second fragment is refused and nothing selects the fragment). 5.x had the function for one of them (DeclarationTables).

Change, to decide

One function of the kernel says which tables a declaration lands on, total over TPH, TPT, TPC, table splitting and entity splitting, and refuses what it has no answer for:

The same function on both sides of a diff, on a model and on its snapshot.

Done when

SchemaResolverTests holds a row per mapping strategy on a model and its compiled snapshot, the 5.x reader's refusal of a TPC root goes, and its fixture gains the hierarchy.

Activity

  1. added this to the 11.0.0 milestone on Nov 14, 2026
  2. added
    enhancement
    package/core
    area/migrations
    on Nov 14, 2026
  3. CaffeinatedCoder commented on Nov 25, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Built in three slices, all merged: #187 (PR #188), #189 (PR #190) and #191 (PR #192). What stays open is #85, the derived type's column named from the base type.

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/migrationsenhancementpackage/core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions