Skip to content

Declarations bound to the model at finalization and stored as segments, not as a string to scan #114

Done

Description

@CaffeinatedCoder

Decided 2026-11-24 by the maintainer: the four points of the proposal below, as written. Bound at model finalization in two steps; stored as segments of three kinds, with a literal as translator text; the stored key computed after binding, and Predicate and KeyTarget.Template as one type with two states and no public SQL string; no reader for a preview.1 snapshot. The plan's section 7 has the row. The declaration for an ignored provider stays open with #22. Built in three slices, each a sub-issue of #111.


Proposal, 2026-11-24. Written after spike F (#177, spikes/F.Binder, 45 tests on Npgsql, SQL Server and SQLite, on the branch spike/177-binder). Each sentence that says "measured" names what the spike shows; everything else is a recommendation.

1. Bind at model finalization: yes, in two steps

  • At the call, the provider's factory checks the lambda and makes its captured values constants. Everything that needs no model is still refused on the line where the lambda is written: a method outside the tables, a member of a scalar. Measured: a captured local left in the tree is read when the model is finalized, with whatever value it has then (Q6).
  • At finalization, a convention binds it. The plugin that adds the wiring convention adds one more, last among the finalizing conventions. Measured there (Q1): a property has its final nullability and its column name, and no type mapping and no store type. The literal comes from IRelationalTypeMappingSource.FindMapping(property), asked of the declared property, and it writes the stored value: an enum as its number or its name, a value object through a converter from ConfigureConventions, a bool stored as text, a DateTime, a Guid. HasConversion<string>() leaves no converter on the property, so reading the property's converter is not enough.
  • The spelling travels with the unbound value. The provider's factory puts it there, so the convention resolves nothing of a provider, and nothing new has to be resolvable while a model is built.
  • The declaration is bound a second time on the finalized model, and a different text is refused. A convention of another package that runs after ours can change what the binding read. Measured: the binding does not see it, the second binding does (Q1).
  • What is bound, and what stays the resolver's. Bound: null compensation and literals. Still resolved at diff time, on both sides: a path's column, so that an object follows a rename, and the store type.
  • The consequence to accept: a column that becomes nullable, or gets another converter, changes the stored text, and the next migration rebuilds the object. For an expression key that is required, since an index serves only the expression the query writes. For a condition it is more than the database needs, and it is what a model that says one thing and an index that says another would otherwise be.

2. Stored as segments

  • Three kinds: text the translator wrote, which reads nothing; a column by its path; and raw SQL a consumer wrote, which reads the whole table, also beside a column. In the annotation, an array in which a string is translator text: ["lower(", {"col":"Email.Value"}, ") = '[email protected]'"], and {"raw":"…"} for the third.
  • A literal is translator text, not a kind of its own. A literal kept with its type could only serve to write it again later, which is the rendering a second time this issue rejects. This is the one place where I leave out what the issue lists.
  • The resolver scans nothing. No quote counting, no brace matching: Predicate.And takes a trailing AND (x) for a top-level conjunct, whatever the precedence #83's and SchemaResolver: paths to columns and SQL, identically on both sides of a diff #43's scanners go.
  • Predicate.And is composition: ["(", …a, ") AND (", …b, ")"], and "already added" is a comparison of segments.
  • A default name is built from the segments: a column's own name, and of text the ASCII letters and digits. Today's rule asks the runtime what a letter is.
  • v becomes 3. KeyTarget.Column stays the case of a path alone.

3. The key, the read model and Redeclare

  • At the call a declaration is refused by its name, or by what it says: the lambda's tree, compared with EF Core's ExpressionEqualityComparer, which compares constants by value. Measured (Q4): x.Tag != "blocked" and x.Tag != tag are refused as one, and only because the captured local is a constant by then.
  • The stored key is computed after binding. A named declaration's key does not change. Measured (Q4): x.Active and x.Active == true pass the call and bind to one text; they are refused at finalization, naming both. The order they were written in has to be kept for that message.
  • Between the call and finalization the declaration is held on the entity type as an object, under a key of the same prefix that no stored key can have. Measured (Q2, Q3): the design-time model, the runtime model, a scaffolded snapshot and a scaffolded compiled model hold text alone, one model build serves both models, and the convention does not run for a snapshot.
  • One type, two states (The lambda factories leave the kernel: Predicate.Of and KeyTarget.Of take no provider and spell SQL as Npgsql does #112, point 2). GetDeclarations, FindDeclaration and Redeclare hand out the same declaration types before and after; a Predicate or a KeyTarget.Template is unbound before finalization and bound after. For that neither shows its SQL as a public string and neither is made from text with new: what stays unmarked is And, equality, and a ToString() for a message. Raw SQL comes in through the provider's factory. A contributor reads the segments through the marked contract.
  • Redeclare amends before finalization. Measured (Q5): the amended declaration is what is bound, and after finalization the model takes no annotation, as today.

4. preview.1's snapshots

No reader. A v of 2 is refused with a message that says to scaffold again, which is the policy of #9 and what preview.1's README says of a database built from a preview. A reader could not recover a converter that was never applied or the dependency of a raw segment, so it would read some snapshots wrongly and say nothing.

Open beside the four

If it is accepted, in this order

  1. Segments as the stored form, v 3, the resolver reading segments. The translator still runs at the call; nothing else changes.
  2. The unbound state, the binding convention and the second binding, with Predicate and KeyTarget in their final public shape (The lambda factories leave the kernel: Predicate.Of and KeyTarget.Of take no provider and spell SQL as Npgsql does #112, point 2).
  3. The translator takes its facts from the model: nullability, converted literals, enums, DateTime and Guid. The parity sweep gets those rows, and The lambda factories leave the kernel: Predicate.Of and KeyTarget.Of take no provider and spell SQL as Npgsql does #112's refusals become support.

Before preview.2. From the architecture debate of 2026-11-14; not decided. Reopens the form of plan section 3.5 and of decision 7 (templates at declaration): the principle stays (what is stored is rendered text, never an expression rendered again on both sides), the moment and the stored form change.

Problem

A lambda becomes a string template where it is written, with no model at hand, and the resolver later finds {Path} by scanning that string. One group of defects follows from each half.

One fact decides where the fix goes: a snapshot is a property bag without converters. A literal can be converted only before it is stored. Nullability and the store type a resolver can read on both sides; the converter it cannot.

Change, to decide

  1. Bind at model finalization. A declaration holds its lambda until the model is finalized; a binder then reads the property, its column, converter, nullability and store type, has the active provider's package spell the SQL, and stores the result. A snapshot and a compiled model hold the bound form and are never translated again.
  2. Stored as segments, not as one string: text, a column by its path, a literal with its type. A raw segment reads the whole table, also beside a column segment. And is composition. A default name is built from the segments by a rule that does not ask the runtime what a letter is.
  3. What it has to survive here: Declare refuses a repeated key at the call, so the logical key is reserved at the call and physical collisions are checked again after binding; FindDeclaration, Redeclare and the read model give one view before and after; a declaration of an inactive provider that the options ignore stays unbound.
  4. preview.1's snapshots: today DeclarationCodec refuses every v but its own. Either a reader for the old v with its resolution epoch, which cannot recover a converter or a raw dependency that was never stored, or the stated policy that a preview.1 snapshot is scaffolded again (SchemaKit: snapshot format v2 and CodoMetis: annotation keys ship in 11.0.0; the 5.x format is read forever (D11) #9).

The alternative, an expression kept and rendered on both sides, is the rendering-version trap 5.x was in, and is rejected.

Done when

The refusals of the lambda factories' issue are support: an enum, a converted property and a nullable column each give the predicate EF Core's query gives, held by the parity sweep on PostgreSQL and on the second provider.

Activity

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

    @CaffeinatedCoder
    OwnerAuthor

    Done in four slices: the stored form (#178, PR #182), the binding at finalization (#179, PR #183), nullability and literals from the model with the second binding (#180, PR #185), and the spelling in the provider's package (#184, PR #186). Spike F (#177, PR #181) measured it first. The declaration for an ignored provider stays open on #22. The default name of an object built from a template kept 5.x's rule and is still the maintainer's to confirm (top of #178).

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/expression-indexesbreakingenhancementpackage/core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions