Fix query shaping for native primitive collections - #38810
Draft
AndriySvyryd with Copilot wants to merge 2 commits into
Draft
Fix query shaping for native primitive collections#38810AndriySvyryd with Copilot wants to merge 2 commits into
AndriySvyryd with Copilot wants to merge 2 commits into
Conversation
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
There was a problem hiding this comment.
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.
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.
Primitive collections with native provider representations were incorrectly treated as JSON strings, causing query compilation failures such as
int[]→stringcoercion errors.Query shaping
string.Default values
"[]"only for JSON string-backed collections.Regression coverage
int[]values, including entity materialization, direct projection, and default-value generation.