Uh oh!
There was an error while loading. Please reload this page.
[release/11.0-rc1] Fix query shaping for native primitive collections - #38810
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
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.
Uh oh!
There was an error while loading. Please reload this page.
* 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>
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.