Repository navigation
fix: build a set from an inline array in a query (#583) - #591
Merged
Merged
Conversation
This was referenced Nov 30, 2026
Since C# 14, Int32Set.From(new[] { 1, 2 }) binds From(params
ReadOnlySpan<T>), so the expression tree holds ReadOnlySpan<T>.op_Implicit
over the array. EF Core evaluates query parameters with the LINQ
interpreter before any plugin sees the query, and the interpreter cannot
call a method that returns a ref struct, so every such query threw. EF Core
rewrites the conversion away for MemoryExtensions only.
An IEvaluatableExpressionFilterPlugin now declares the array-to-span
conversion not evaluatable (the interpreter fails on every expression that
holds one, so nothing that evaluates today changes). The call then reaches
the query interceptor, which builds an array of constants into the set
through From(IEnumerable<T>) and inlines it, as EF Core does with an inline
Parse; hands an array that reads a column to the IEnumerable overload; and
refuses an array of captured variables, whose values are bound after the
rewrite, naming the two spellings that work.
Two seed patches touched the interceptor's rewriter chain and are
refreshed against it; their defects are unchanged.
Found-By: CA
Defect-Class: SQL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CaffeinatedCoder
force-pushed
the
fix/583-inline-set-from-array
branch
from
November 30, 2026 12:41
d6aec89 to
15c27f2
Compare
This was referenced Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #583
Problem
b.Codes.IsSubsetOf(Int32Set.From(new[] { 1, 2 }))threw "An exception was thrown while attempting to evaluate a LINQ query parameter expression", for every set and range set type. Since C# 14 the call bindsFrom(params ReadOnlySpan<T>), so the tree holdsReadOnlySpan<T>.op_Implicit(array). EF Core evaluates query parameters with the LINQ interpreter, which cannot call a method returning a ref struct.What EF Core 11 does itself:
ExpressionTreeFuncletizerrewrites the span conversion away only forMemoryExtensions(Contains,Min,Max,SequenceEqual), hard-coded, before evaluation. It has no hook for that step. The query interceptor (RangeSetContainsRewriter's home) runs after parameter extraction, so it cannot fix this alone.Change
Query/ArraySpanConversionFilterPlugin.cs(internal, new): anIEvaluatableExpressionFilterPluginthat declaresSpan<T>/ReadOnlySpan<T>.op_Implicit(T[])not evaluatable. Every expression holding one fails in the interpreter today, so nothing that evaluates now changes. EF Core then keeps the array inline, with its elements as constants or parameters.ValueRangesQueryExpressionInterceptor.SpanFromRewriter(new, runs first) handlesXSet.From(op_Implicit(array))for a registered set or range set type:From(IEnumerable<T>)and inlines it as a constant. The SQL is the same asXSet.Parse("{1,2}", null)inline.IEnumerable<T>overload. A final projection reads the array and builds the set in memory.IEnumerable<T>. Their values are bound after the rewrite runs. Before, EF Core threw the interpreter error.NpgsqlValueRangesServiceCollectionExtensions: registers the plugin.test/oracles/seeds/compareto-null-operand-compared-as-sql-null.patchandlower-bound-comparer-runs-as-sql.patch: refreshed. They edit the interceptor's rewriter chain, which gained a link. Their defects are unchanged.Fixedline in the root and EF changelogs, under the 11.0.0-preview.3 section feat: typed Overlaps for SchemaKit exclusion constraints in a fifth package (#540) #592 opened. Rebased on main after feat: typed Overlaps for SchemaKit exclusion constraints in a fifth package (#540) #592.Tests
InlineSetFromArrayTests(EF translation, no database):Booking(23 types, discovered), it buildsFrom(op_Implicit(new[] { x }))as the compiler writes it. It expects the SQL of the same set inlined as a constant.AsWrittenInCSharpchecks the compiler's own tree againstInt32Set.Parse.Reverted: with the plugin's registration removed, 25 of the 27 fail with the original interpreter exception.
Local: EF translation 479/479, EF NodaTime translation 114/114, conventions 431/431. Not run locally: the integration projects (no new SQL shape; the inlined constant is the existing constant path).
🤖 Generated with Claude Code