Skip to content

Fix compiled queries with IsOneOf and array parameters#4217

Merged
jeremydmiller merged 1 commit intomasterfrom
fix/4202-compiled-query-string-collection
Mar 29, 2026
Merged

Fix compiled queries with IsOneOf and array parameters#4217
jeremydmiller merged 1 commit intomasterfrom
fix/4202-compiled-query-string-collection

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

Fixes compiled queries that use IsOneOf() with array-typed parameters (e.g., string[]) and IQueryPlanning. Previously, string[] properties on compiled query classes were incorrectly classified as Include members (because string[] implements IList<string>), causing the parameter to be hardcoded with the template value instead of reading from the query instance at runtime.

Root cause: CompiledQueryPlan.sortMembers() checked IList<> before checking if the type was an array with a known parameter finder. Since string[] implements IList<string>, it was added to IncludeMembers instead of QueryMembers.

The fix has four parts:

  1. CompiledQueryPlan.sortMembers: Check for array types with known element-type finders before the IList<> check
  2. ArrayParameterFinder<T>: New finder that matches T[] types and provides unique array values for query planning
  3. QueryMember.tryToFind: Use structural array comparison instead of reference equality when matching parameter values
  4. ParameterUsage.generateSimpleCode: Emit correct composite NpgsqlDbType (Array | ElementType) for array parameters

Supersedes #4202 (includes the test from that PR plus the fix)

Test plan

  • New test can_search_isOneOf_strings_with_compiled_queries_and_query_planning passes
  • All 1248 LinqTests pass with zero regressions
  • Solution compiles via nuke compile

🤖 Generated with Claude Code

…anning

Array-typed properties (string[], Guid[], int[], etc.) on compiled query
classes were incorrectly classified as Include members because string[]
implements IList<string>. This caused IsOneOf() parameters to be
hardcoded with template values instead of reading from the query instance.

The fix has four parts:
1. CompiledQueryPlan.sortMembers: check for array types with known
   element-type finders BEFORE the IList<> check
2. ArrayParameterFinder<T>: new finder that matches T[] types and
   provides unique array values for query planning
3. QueryMember.tryToFind: use structural array comparison instead of
   reference equality when matching parameter values
4. ParameterUsage.generateSimpleCode: emit correct composite
   NpgsqlDbType (Array | ElementType) for array parameters

Closes #4202

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit d313629 into master Mar 29, 2026
1 of 6 checks passed
@jeremydmiller jeremydmiller deleted the fix/4202-compiled-query-string-collection branch March 29, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant