Skip to content

SchemaResolver: paths to columns and SQL, identically on both sides of a diff #43

Open
2 of 2 issues completed

Description

@CaffeinatedCoder

From #85, decided 2026-11-12: a path has to be able to name a property of a derived type that shares the declaring type's table (((Stay)x).GuestId on Reservation). Two sibling types may each have a property of one name, so the stored path has to say which type it means. To settle before epoch 1 freezes.


2026-11-12, merged (PR #70, closed #69): renames. The resolver takes EF Core's renames for the source side of a diff: SQL and dependencies take the target's table and column names, a default name is still built from the source's own. Still open here: JSON members (with #25, #27), TPC, the corpus (#33) and store facts, and the two ported limits to decide before epoch 1 is frozen.


2026-11-12, merged (#59, closed #58): the first slice. SchemaResolver has Column(path), Template(sql) and Name(declared, prefix, parts), and every SqlFragment records what it reads (Dependencies: the columns of its placeholders, or the whole table for SQL without one). The kernel's resolver reads metadata only and is tested on a configured model and on its compiled snapshot alike, on Npgsql, SQL Server and SQLite. The API takes paths and templates as the declaration holds them; Target(KeyTarget) and Predicate(…) from the design come with the declaration values of the first provider vocabulary.

Still open here:

To decide before epoch 1 is frozen by a release. Two rules are ported from 5.x with their known limits:

  • The converter-member check compares types only, so a second member of the stored type (Email.Alias, also a string) resolves to the column like Email.Value.
  • Only single quotes are tracked in a template. A {Path} inside a double-quoted identifier, a dollar-quoted string or a comment is replaced.

A gap in the backlog, found while writing the handoff of 2026-11-11: the resolver is named in the plan and the design and in the bodies of #7, #24 and #27, and no issue owns it. In 5.x it is the largest and most fragile part of the differ.

Problem

A declaration holds property paths and templates. A descriptor holds identifiers and SQL. Something has to turn one into the other, once per table and identically for both sides of a diff, and it is where most of the 5.x bugs lived: a snapshot that has no converters, a renamed table or column, a JSON member rendered differently from the query that should use the index, a column that no longer exists.

Change

SchemaResolver, handed to a contributor's Resolve (design, section 9.4; plan, section 3.5):

  • Table, Target(KeyTarget) → SqlFragment, Predicate(…) → SqlFragment, Name(declared, prefix, parts) → Identifier (the default-name rule, length-checked through the dialect), and the store facts of a target.
  • It walks EF's relational model with StoreObjectIdentifier: complex-type columns and HasColumnName, the converter-member unwrap, the property-bag rule for snapshots, JSON members rendered as the provider's queries render them, the JSON container as a plain column, placeholders outside single-quoted literals only.
  • The mapping is the declared property's, found through the property and the store object, never IColumn.PropertyMappings[0].
  • Epochs: each declaration carries its resolution epoch r; an unknown epoch is an error; the golden corpus (Golden corpus per renderer epoch, with snapshot fixtures #33) fails a change without a new one.
  • Renames: the source side resolves under the table and column names the inner differ's RenameTableOperation and RenameColumnOperation give, so a rename does not rebuild what reads the column.
  • Every fragment records the columns it reads, which is what ImpactOf (Change planning and impact: SchemaChange, BaseChange, ImpactOf, dependencies #24) is asked about. Raw SQL without placeholders depends on every column of its table.
  • TPC: where a declaration lands (DeclarationTables in 5.x), and the refusals that go with it.
  • It is a diff-time service: it may need the model, so it is never a constructor dependency of the differ or the generator.

Done when

  • A snapshot round trip (a real generated snapshot compiled with Roslyn, as 5.x's SnapshotRoundTripTests does) resolves every kind of path alike on both sides, at the top level and inside a complex type.
  • Each JSON-member rendering is asserted against EF Core's own ToQueryString().
  • The corpus (Golden corpus per renderer epoch, with snapshot fixtures #33) has a triple per rule and epoch.

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

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

    @CaffeinatedCoder
    OwnerAuthor

    From the pre-preview sweep of main @ 948496a, 2026-11-14. #101 is the TPC case as a defect (a concrete root reaches one table). Beside it, what the reviews read in the resolver and did not turn into issues, for the decisions before epoch 1 is frozen. None was run unless it says so.

    • The converter-member rule, a second face. A converter that changes the value, not only wraps it: Email.Value == "foo" is written against the column, which holds "mail:foo". And a bool stored as text: where: x => x.Active gives WHERE (active), which PostgreSQL refuses. A literal is written as the model's value where the template is made, with no type mapping at hand. An enum comparison is refused for that reason already.
    • Only single quotes are tracked, as noted above. Seen from the 5.x reader: a raw WithExpression text with a brace in a dollar-quoted string or a quoted identifier would have a placeholder replaced that 5.x wrote as it was.
    • A template that mixes {A} with a raw "B" records A alone. Measured: dropping B fails with 2BP01, so it is loud, not a loss. It takes a hand-built KeyTarget.Template.
    • NameTokens.Of keeps a char by char.IsLetterOrDigit: a supplementary letter is two surrogates and both go, and what counts as a letter moves with the runtime's Unicode tables. 5.x used the same rule on .NET 10, so a default name of 5.x and one computed here can differ for a character assigned in between. That is a rename nobody asked for, not a loss.
    • DeclarationCodec.Fold upper-cases with the runtime's tables for a key under IgnoreCase. No declaration of today uses it; the first that does has a key that can move with the runtime, the class CanonicalJson was written against.
    • An entity split over two tables (SplitToTable) resolves against its main table only: a column in the other fragment is refused, and nothing selects the fragment. Read, not run.
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