Skip to content

Fix query shaping for native primitive collections - #38810

Draft
AndriySvyryd with Copilot wants to merge 2 commits into
mainfrom
copilot/query-shaper-primitive-collection-fix
Draft

Fix query shaping for native primitive collections#38810
AndriySvyryd with Copilot wants to merge 2 commits into
mainfrom
copilot/query-shaper-primitive-collection-fix

Conversation

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Primitive collections with native provider representations were incorrectly treated as JSON strings, causing query compilation failures such as int[]string coercion errors.

  • Query shaping

    • Apply JSON deserialization only when the converter’s provider CLR type is string.
    • Preserve normal converter handling for native arrays during entity materialization and direct projection.
  • Default values

    • Generate "[]" only for JSON string-backed collections.
    • Generate empty native arrays for array-backed mappings.
  • Regression coverage

    • Cover enum collections mapped to native int[] values, including entity materialization, direct projection, and default-value generation.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix query shaper for native collection support Fix query shaping for native primitive collections Aug 14, 2026
Copilot AI requested a review from AndriySvyryd August 14, 2026 20:48
@AndriySvyryd
AndriySvyryd requested a lite review from Copilot August 15, 2026 01:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a regression in relational query shaping where primitive collections were assumed to be stored as JSON strings, which breaks providers that map primitive collections to native database collection types (e.g., native arrays). The fix tightens the JSON-deserialization path to only apply when the converter’s provider CLR type is actually string, and adjusts default provider value generation accordingly, with a regression test covering native array mappings.

Changes:

  • Restrict primitive-collection JSON reader/writer handling in the shaper to mappings whose converter provider CLR type is string.
  • Update RelationalTypeMapping.GetDefaultProviderValue() so "[]" is generated only for JSON-string-backed primitive collections, while native array-backed mappings get empty arrays.
  • Add relational tests validating materialization, projection, and default provider value behavior for native primitive collection mappings.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/EFCore.Relational.Tests/Query/RelationalShapedQueryCompilingExpressionVisitorTest.cs Adds regression tests for native primitive collection mappings (materialization, projection, default value).
src/EFCore.Relational/Storage/RelationalTypeMapping.cs Generates "[]" only when the provider type is string; otherwise produces empty native arrays for array-backed mappings.
src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs Gates the JSON primitive-collection shaping path on converter.ProviderClrType == typeof(string) to avoid invalid coercions for native arrays.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

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.

Query shaper assumes primitive collections are stored as JSON strings, breaking providers with native collection support (11.0 preview 7 regression)

3 participants