Skip to content

[release/11.0-rc1] Fix query shaping for native primitive collections - #38810

Merged
AndriySvyryd merged 2 commits into
release/11.0-rc1from
copilot/query-shaper-primitive-collection-fix
Aug 21, 2026
Merged

[release/11.0-rc1] Fix query shaping for native primitive collections#38810
AndriySvyryd merged 2 commits into
release/11.0-rc1from
copilot/query-shaper-primitive-collection-fix

Conversation

CopilotAI 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>
CopilotAI changed the title [WIP] Fix query shaper for native collection supportFix query shaping for native primitive collectionsAug 14, 2026
CopilotAI requested a review from AndriySvyrydAugust 14, 2026 20:48
@AndriySvyryd
AndriySvyryd requested a lite review from CopilotAugust 15, 2026 01:14

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.

FileDescription
test/EFCore.Relational.Tests/Query/RelationalShapedQueryCompilingExpressionVisitorTest.csAdds regression tests for native primitive collection mappings (materialization, projection, default value).
src/EFCore.Relational/Storage/RelationalTypeMapping.csGenerates "[]" only when the provider type is string; otherwise produces empty native arrays for array-backed mappings.
src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.csGates 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.

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review August 17, 2026 16:27
@AndriySvyryd
AndriySvyryd requested a review from a team as a code ownerAugust 17, 2026 16:27
@AndriySvyryd
AndriySvyryd changed the base branch from main to release/11.0-rc1August 17, 2026 18:13
@AndriySvyrydAndriySvyryd changed the title Fix query shaping for native primitive collections[release/11.0-rc1] Fix query shaping for native primitive collectionsAug 18, 2026
@AndriySvyryd
AndriySvyryd merged commit 62f1eee into release/11.0-rc1Aug 21, 2026
20 of 21 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/query-shaper-primitive-collection-fix branch August 21, 2026 19:34
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-rc1 milestone Aug 21, 2026
wtgodbe added a commit that referenced this pull request Aug 22, 2026
* Merge pull request #38837 from dotnet/darc-release/11.0-rc1-397e9f16-6eec-4c2a-a4d8-e46b06f86e54
[release/11.0-rc1] Source code updates from dotnet/dotnet
* [release/11.0-rc1] Source code updates from dotnet/dotnet (#38841)
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk, Microsoft.DotNet.Build.Tasks.Templating, Microsoft.DotNet.Helix.Sdk (Version 11.0.0-beta.26420.118 -> 11.0.0-beta.26421.101)
Microsoft.Extensions.Caching.Memory, Microsoft.Extensions.Configuration, Microsoft.Extensions.Configuration.EnvironmentVariables, Microsoft.Extensions.Configuration.Json, Microsoft.Extensions.DependencyInjection, Microsoft.Extensions.DependencyModel, Microsoft.Extensions.HostFactoryResolver.Sources, Microsoft.Extensions.Logging, Microsoft.NETCore.App.Ref, Microsoft.NETCore.Platforms, System.Formats.Asn1, System.Runtime.Caching, System.Text.Encodings.Web, System.Text.Json (Version 11.0.0-rc.1.26420.118 -> 11.0.0-rc.1.26421.101)
[[ commit created by automation ]]
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
* [release/11.0-rc1] Fix query shaping for native primitive collections (#38810)
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
* [release/11.0-rc1] Preserve discriminating ORDER BY for many-to-many collections (#38811)
Fixes#38770
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
---------
Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Sign up for freeto 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)

4 participants

@SamMonoRT@AndriySvyryd