Repository navigation
Description
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 fromConfigureConventions, aboolstored as text, aDateTime, aGuid.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.Andis 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.
vbecomes 3.KeyTarget.Columnstays 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"andx.Tag != tagare 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.Activeandx.Active == truepass 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,FindDeclarationandRedeclarehand out the same declaration types before and after; aPredicateor aKeyTarget.Templateis unbound before finalization and bound after. For that neither shows its SQL as a public string and neither is made from text withnew: what stays unmarked isAnd, equality, and aToString()for a message. Raw SQL comes in through the provider's factory. A contributor reads the segments through the marked contract. Redeclareamends 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
- A declaration for a provider the options ignore (A declaration for another provider is an error, unless the options ignore that provider #22) cannot be bound, and a snapshot cannot hold an object. I would leave it out of the finalized model: a context of another provider has migrations of its own. To decide with A declaration for another provider is an error, unless the options ignore that provider #22.
- Not measured: the real translator split in two passes; a path through a complex type, into JSON, or to a column two types share;
dotnet efout of process on a packed consumer.
If it is accepted, in this order
- Segments as the stored form,
v3, the resolver reading segments. The translator still runs at the call; nothing else changes. - The unbound state, the binding convention and the second binding, with
PredicateandKeyTargetin 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). - The translator takes its facts from the model: nullability, converted literals, enums,
DateTimeandGuid. 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.
- No model: nullability is the CLR annotation's and not the column's; a literal compared with a converted property is written as the model's value and not the stored one (
x.Activeon aboolstored as text givesWHERE (active)); an enum comparison andDateTimeandGuidliterals are refused because no type mapping is at hand; everyConvertis dropped (A narrowing cast in a lambda is left out of the template: (int)x.Amount == 2 is stored as {Amount} = 2 #103). - A string:
Predicate.Andsearches SQL text for a conjunct (Predicate.And takes a trailing AND (x) for a top-level conjunct, whatever the precedence #83); a brace in a dollar-quoted string or a quoted identifier is taken for a placeholder; a template that mixes{A}with a raw"B"recordsAalone; a default name is built from the template's characters by the runtime's Unicode tables.
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
- 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.
- 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.
Andis composition. A default name is built from the segments by a rule that does not ask the runtime what a letter is. - What it has to survive here:
Declarerefuses a repeated key at the call, so the logical key is reserved at the call and physical collisions are checked again after binding;FindDeclaration,Redeclareand the read model give one view before and after; a declaration of an inactive provider that the options ignore stays unbound. preview.1's snapshots: todayDeclarationCodecrefuses everyvbut its own. Either a reader for the oldvwith its resolution epoch, which cannot recover a converter or a raw dependency that was never stored, or the stated policy that apreview.1snapshot 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
CaffeinatedCoder commentedon Nov 25, 2026
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).