Skip to content

feat!: a lambda is bound from the model's facts - #185

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
feat/180-model-facts
Nov 25, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
feat/180-model-facts

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #180

Slice 3 of the binder (#114, decided 2026-11-24), after #178 and #179.

Problem

Since #179 a lambda in a declaration becomes SQL when its model is finalized, but it was still translated from the C# types alone. So:

  • Null compensation followed the C# annotation, not the column. IsRequired() on a string? still got OR … IS NULL, and IsRequired(false) on a string got none.
  • A value only the model can write was refused where the lambda is written: an enum compared with a value, a value object, a DateTime, a Guid.
  • A bool stored as something else (HasConversion<string>(), a converter to 'Y'/'N') was written as a boolean column.

Change

  • TranslationFacts is what the translator asks for what a lambda cannot say. At the call the facts are the C# types', and a value only the model can write is the mark LambdaTranslator.BoundLater, which is never stored. At finalization they are ModelFacts: a column can be null when the property or a complex property on its path is nullable in the model, and a value compared with a property is written by that property's type mapping, through its converter.
  • The mapping is asked of IRelationalTypeMappingSource. No property holds its mapping while a model is finalized (spike F).
  • A boolean stored as something else is compared with what true is stored as, and a negation with what false is stored as, as EF Core writes both.
  • Refused at finalization, with the property named: an order comparison on what a converter stores as text, and a value the mapping refuses. A converter between numbers, or from an enum to its number, keeps the order.
  • SchemaKitBindingCheckConvention binds every declaration a second time, first on the finalized model, and refuses a different result: a convention of another package that runs after the binding can change a column's nullability or a property's conversion.
  • PropertyPaths.Find is the one walk from a path to a property, for the resolver and for the facts.

On SQL Server a value compared with a property is now SQL Server's own literal (CAST(1 AS bit), N'blocked'), since the mapping writes it. The second provider's tests said the one spelling's TRUE is refused there; that comparison is accepted now.

A DateTime that is not UTC cannot be written for Npgsql's timestamp with time zone and is refused by the mapping.

Not here: the move of the accepted constructs and the spelling to the provider's package, #184.

breaking: a condition bound from a lambda can come out differently than under preview.1 and the earlier slices (nullability from the model, literals from the mapping).

Tests

  • ModelFactsBindingTests: 13 conditions, each asserted as bound text and compared with EF Core's ToQueryString() for the same lambda on the same model; the two refusals at finalization; a convention registered after SchemaKit's that makes a column nullable, which the second binding refuses.
  • The parity sweep translates with the model's facts. Against main: 72 fewer refusals at the declaration, 60 more rows that agree with EF Core, 12 more that differ. waivers.txt is unchanged and the sweep passes.
  • Offline: 750 (kernel), 195 (PostgreSQL package), 85 (second provider). Live: 4 and 73 on PostgreSQL 16 and on 18, 86 on SQL Server 2022. The consumer smoke test: 47 rows.

Each rule was changed in place and the tests run; a test failed for each of eleven:

Rule changed Fails
Nullability from the annotation, not the model A_condition_is_bound_from_the_models_facts, Each_is_what_EF_Core_writes_for_the_lambda_in_a_query, A_fact_that_changes_after_the_binding_is_refused_on_the_finalized_model
The translator's own literal, not the mapping's A_condition_is_bound_from_the_models_facts, Each_is_what_EF_Core_writes_for_the_lambda_in_a_query, A_value_the_columns_type_cannot_hold_is_refused
No order rule for a converter An_order_by_what_a_converter_stores_as_text_is_refused
A stored flag written as a boolean column A_condition_is_bound_from_the_models_facts, Each_is_what_EF_Core_writes_for_the_lambda_in_a_query
A negated stored flag wrapped in NOT the same two
No second binding A_fact_that_changes_after_the_binding_is_refused_on_the_finalized_model
A mapping's refusal not wrapped the sweep's two tests, A_value_the_columns_type_cannot_hold_is_refused
An enum against a value refused What_a_predicate_cannot_say_is_refused and two more in the kernel, three in ModelFactsBindingTests
Every converter loses its order a test failed; first form did not compile, redone
The mapping asked of the property alone a test failed; first form did not compile, redone
A mark bound without a model a test failed; redone

For the last three the run that failed was a second one whose output I did not keep; the first eight are from the kept log.

🤖 Generated with Claude Code

When its model is finalized, a lambda in a declaration is translated with
the model's facts instead of the C# types': a column can be null when the
property, or a complex property on its path, is nullable in the model, and
a value compared with a property is written by that property's type
mapping, through its converter.

An enum, a value object, a DateTime, a Guid and a bool stored as something
else are written that way; at the call they are a mark that is never
stored. An order comparison on what a converter stores as text is refused
at finalization, and so is a value the mapping refuses.

Each declaration is bound a second time on the finalized model, and a
different result is refused: a convention that runs after the binding can
change a column's nullability or a property's conversion.

ModelFactsBindingTests compares each condition with EF Core's
ToQueryString() for the same lambda on the same model, and the parity
sweep translates with the model's facts.

Closes #180

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 25, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request breaking Changes an answer or a signature package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL area/expression-indexes Expression, typed lambda and JSON member indexes labels Nov 25, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit e52a499 into main Nov 25, 2026
11 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/180-model-facts branch November 25, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/expression-indexes Expression, typed lambda and JSON member indexes breaking Changes an answer or a signature enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binder, slice 3: the translator takes nullability and literals from the model

1 participant