Skip to content

feat: the lambda translator in the kernel, 5.x's expressions and predicates with null compensation - #72

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
feat/lambda-translator
Nov 12, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
feat/lambda-translator

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #71

The first slice of #26, which stays open. It comes before the PostgreSQL package (#25) by the maintainer's decision of 2026-11-12, so that an exclusion constraint in preview.1 takes a lambda filter.

Problem

A declaration holds SQL templates, and nothing in SchemaKit turned a lambda into one.

Change

Translation/Internal/LambdaTranslator.cs: NpgsqlLinqIndexTranslator of 5.x, ported in full, internal. Expression(lambda) and Predicate(lambda) return a template in the resolver's grammar.

  • Expressions: property paths, ToLower, ToUpper, Trim, TrimStart, TrimEnd, Substring, Replace, Length, concatenation, ??, Nullable<T>.Value, constants and captured values as literals.
  • Predicates: the six comparisons, &&, ||, !, boolean members, HasValue, comparisons with null, with EF Core's null compensation and the negation pushed down to a comparison that can be NULL.
  • Refusals at the declaration: an enum comparison, a DateTime or Guid literal, a member of a scalar, a method outside the tables, a lambda over more than one parameter.
  • The tables are kept (StringMethods, ValueMembers, ValueOperators, ComparisonOperators, LogicalOperators, LiteralTypes), for the sweep and the analyzer.

What differs from 5.x, on purpose:

  • No brace escape. 5.x doubled a brace inside a string literal for its template grammar and undid that for filters. The resolver has one grammar and takes nothing inside quotes for a placeholder, so a literal is written as it is. A test resolves '{x}' through the kernel's resolver on a model and on its snapshot.
  • The messages point at "write that part as SQL" and no longer at 5.x's overloads.
  • A lambda over two parameters is refused; 5.x took the first.

The spellings are PostgreSQL's. Nothing calls the translator yet: the declaration values that do (Predicate.Of, Sql.Raw) come with the first provider vocabulary (#25).

Not here (stays in #26)

  • The parity sweep against EF Core's ToQueryString() and the answers-alike run on PostgreSQL 18. Until it is ported, what holds the templates is these rule tests; that a template is what EF Core's queries write is not checked here.
  • [SchemaFunction] markers for other packages.

Tests

Kernel tests without a server, on SDK 11.0.100 in the checkout: 380 before, 398 after. Probes: 125 pass. The PostgreSQL integration tests did not run locally; CI runs them.

LambdaTranslatorTests has a test per rule, with the failure the rule was written after in its comment. One expectation of mine was wrong and the port was right: a negated captured flag is NOT (TRUE), not folded to FALSE, as 5.x wrote it.

Each rule undone in a scratch copy, 20 in all:

Undone Fails
Trim without the provider's characters; substr for substring the string-method test; the substring test
A substring start is not moved by one; a known start is not folded the substring test (each)
A nullable operand of a concatenation is not coalesced; the coalesce is not cast the concatenation test (each)
The thread's culture in a number; a quote in a literal is not doubled the literal test (each)
Any formattable value is a literal; a member of a scalar is a path; a lambda over two entities is taken the refusal test (each)
No null compensation for !=; for == on two nullables the nullable-comparison test (each)
A comparison with null is an equality the null-test test, the resolver test
A negation is wrapped, never pushed down; a negated nullable comparison is its complement; no De Morgan the negation test (each)
A char is compared as its code the char test
An enum is compared the predicate-refusal test
The null test of a function is on the function the nullable-comparison test, the null-test test

🤖 Generated with Claude Code

…icates with null compensation

NpgsqlLinqIndexTranslator of 5.x, ported in full and internal. A lambda
becomes a template where it is written: property paths stay placeholders
for the resolver, string methods are spelled as Npgsql's queries spell
them, and a comparison that can be NULL is written as EF Core writes it, so
that a predicate keeps the rows C# keeps. Enums, DateTime and Guid literals,
members of a scalar and methods outside the tables are refused at the
declaration. The accepted constructs stay data.

A literal is written as it is: the resolver has one grammar and takes
nothing inside quotes for a placeholder, so 5.x's brace escape is gone.

Closes #71

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 12, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) area/expression-indexes Expression, typed lambda and JSON member indexes labels Nov 12, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit b4c6209 into main Nov 12, 2026
6 of 7 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/lambda-translator branch November 12, 2026 09:55
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 enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lambda translator, first slice: the 5.x translator in the kernel, expressions and predicates with null compensation

1 participant