Repository navigation
feat: translate Contains over a captured collection of value sets - #75
Merged
Merged
Conversation
wanted.Contains(r.Tags) over a captured list, array or IEnumerable of value sets went out as one array parameter (r."Tags" = ANY (@wanted)). A value set is already an array, so that parameter is an array of arrays, which PostgreSQL does not have, and Npgsql threw InvalidCastException writing T[][] for every family. The query interceptor now switches such a parameter to EF Core's MultipleParameters mode: one parameter per set, so Contains runs as IN (@p1, @p2, ...) and Any/Count read from VALUES. Equality of canonical arrays is set equality, so the rows match the in-memory answer. Only a collection whose effective mode is Parameter is changed; Constant and EF.Constant keep their literals. EF.Parameter(wanted), which asks for the impossible single parameter, throws in translation and says to remove it. A server-side Union stays refused under IN by ValueSetSqlGuard. Closes #46 Found-By: RV Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
CaffeinatedCoder
force-pushed
the
fix/list-contains-value-set
branch
from
October 17, 2026 18:13
ab2fb6c to
d076560
Compare
This was referenced Oct 17, 2026
Closed
This was referenced Oct 17, 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 #46
Problem
wanted.Contains(r.Tags)over a captured collection of value sets (List<T>,T[],IEnumerable<T>,HashSet<T>) threwInvalidCastExceptionin Npgsql for every value set family:Npgsql sends a parameterized collection as one array parameter. A value set is already a PostgreSQL array, so that parameter would be an array of arrays, which PostgreSQL doesn't have.
Any/Countover the collection (unnest(@wanted)) failed the same way. A constant list,EF.Constantand an inlinenew[] { … }already translated toIN (…)and answered correctly. The full repro matrix is in the issue comment.Change
ValueRangesQueryExpressionInterceptorswitches aQueryParameterExpressionwhose element type is a registered value set, and whose effective mode isParameter, to EF Core 10'sParameterTranslationMode.MultipleParameters. Each set is bound as its own parameter through its own mapping.ContainsbecomesIN (@wanted1, @wanted2, …), andAny/Countread fromVALUES (@wanted1), (@wanted2). Equality of two canonical arrays is set equality, so the rows match the in-memory answer. This is the same SQL the constant and inline forms already produced.ConstantorMultipleParameters, andEF.Constant(wanted), keep their mode.EF.Parameter(wanted)explicitly asks for the single array parameter that can't exist, so it now throwsInvalidOperationExceptionin translation and says to remove it.Unionstays refused underINbyValueSetSqlGuard, with its equality message. Before, it was refused under= ANYwith the generic one.ValueSetSqlGuarditself is unchanged.E36intest/oracles/claims.json, and### Addedlines in the root and EF Core changelogs. No candidate was keyed to list.Contains(valueSetColumn) throws InvalidCastException in Npgsql #46.Side finding, filed as #71: a captured
List<Int32Range>fails too, with42809 op ANY/ALL (array) requires array on right side.Tests
SetCollectionTranslationTests(no database) checks the wholeWHEREclause for a list, an array, a wrapper arity'sIEnumerable,NOT INandAnyoverVALUES. It also covers theEF.Parameterrefusal,EF.Constantand theConstantcontext mode, which keep their literals, theUnionrefusal, and aList<string>that still binds as= ANY (@wanted).SetCollectionContainsTests(live PostgreSQL) runs each value set family against two rows: all closed BCL families, the nullable column withnullin the list, all five NodaTime sets and all fifteen wrapper arities. Each runs as an array, aListand anIEnumerable, together with its negation, and is compared with the in-memory answer. Where the family allows it, the wanted set is built differently from the stored one: another order, a duplicate, another offset, another decimal scale. Also covered: the issue's query, an empty list,Any/Count, theEF.Parameterrefusal and theUnionrefusal, all executed.InvalidCastExceptionwritingString[][],Int16[][],DateOnly[][],LocalDate[][]and so on. TheEF.Parametertest catchesInvalidCastExceptionwhere it expectsInvalidOperationException. TheUniontest gets the generic "This use of it" message. Seven of the ten translation tests fail too. The three that pass either way pin paths the fix must leave alone:EF.Constant, theConstantmode andList<string>.dotnet teston the whole solution, integration included: green.🤖 Generated with Claude Code