Skip to content

Fix SQL Server split-query projections of primitive JSON collections - #39294

Merged
AndriySvyryd merged 3 commits into
mainfrom
copilot/fix-jsoncolumn-nullreference-exception
Nov 5, 2026
Merged

AndriySvyryd merged 3 commits into
mainfrom
copilot/fix-jsoncolumn-nullreference-exception

Conversation

Copilot AI commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Projecting a JSON-mapped primitive collection through an identity Select with AsSplitQuery can throw NullReferenceException. The OPENJSON ordering rewrite can create a value column before its type mapping is initialized.

context.Entities.AsSplitQuery()
    .Select(e => new { e.Id, Codes = e.Codes.Select(code => code) });
  • Type mappings
    • Initialize the raw nvarchar(max) mapping before use.
    • Preserve the original element mapping, including converters, when no SQL cast is needed.
  • Regression coverage
    • Cover synchronous and asynchronous projections of strings and converted elements.
    • Add SQL Server baselines and assert SQLite’s existing APPLY limitation.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix NullReference exception for JsonColumn with primitive collection Fix SQL Server split-query projections of primitive JSON collections Oct 16, 2026
Copilot AI requested a review from AndriySvyryd October 16, 2026 22:12
Comment thread .agents/skills/query-pipeline/SKILL.md Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Agent harness evaluation deferred

This PR affects: query-pipeline. Automatic evaluation is deferred because this PR is currently marked as draft. Once it is ready for review, the usual author authorization rules apply. A contributor with write access can comment /eval or /eval component-name, or run the workflow manually for pull request #39294.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>

Copilot AI 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.

🟢 Approval recommended

The localized fix has targeted regression coverage and no identified blocking defects; database-backed tests were not executed.

No open issues 🎉

What changed in this PR

Fixes SQL Server split-query projections of primitive JSON collections by correcting type mappings in the OPENJSON rewrite.

Changes:

  • Initializes raw JSON mappings before use and preserves element converters.
  • Adds synchronous/asynchronous regressions and provider-specific assertions.
  • Documents the mapping invariant in query-pipeline guidance.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Query/​PrimitiveCollectionsQuerySqlServerTest.cs Adds SQL Server baselines.
test/​EFCore.SqlServer.FunctionalTests/​Query/​PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs Adds native JSON baselines.
test/​EFCore.SqlServer.FunctionalTests/​Query/​PrimitiveCollectionsQueryOldSqlServerTest.cs Covers older compatibility behavior.
test/​EFCore.Sqlite.FunctionalTests/​Query/​PrimitiveCollectionsQuerySqliteTest.cs Asserts SQLite’s APPLY limitation.
test/​EFCore.Relational.Specification.Tests/​Query/​PrimitiveCollectionsQueryRelationalTestBase.cs Adds shared string and converter regressions.
src/​EFCore.SqlServer/​Query/​Internal/​SqlServerJsonPostprocessor.cs Initializes and preserves required mappings.
.agents/​skills/​query-pipeline/​SKILL.md Documents mapping preservation requirements.

Review effort: Balanced

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 17, 2026 04:30
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner October 17, 2026 04:30
@AndriySvyryd
AndriySvyryd requested review from cincuranet and a balanced review from Copilot October 17, 2026 04:30

Copilot AI 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.

🟢 Approval recommended

The localized fix addresses the reported mapping failure and converter preservation with focused regression coverage and no identified blocking issues.

No open issues 🎉

Review effort: Balanced

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main 2e88827 copilot/fix-jsoncolu... cad1b21 +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 2e88827 copilot/fix-jsoncolu... cad1b21 +/-
src/EFCore.Rela...CommandCache.cs 100% 98% -2%
src/EFCore.Rela...erExtensions.cs 96% 96% 0%
src/EFCore.SqlS...ostprocessor.cs 99% 99% 0%
src/EFCore.Abst...erExtensions.cs 100% 100% 0%
src/EFCore.Cosm...nsExtensions.cs 82% 82% 0%
src/EFCore.Desi...onExtensions.cs 100% 100% 0%
src/EFCore.Desi...viderFactory.cs 95% 95% 0%
src/EFCore.Desi...CSharpHelper.cs 96% 96% 0%
src/EFCore.Desi...elExtensions.cs 98% 98% 0%
src/EFCore.Desi...hotGenerator.cs 99% 99% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) October 31, 2026 00:32
@AndriySvyryd
AndriySvyryd merged commit b4b1829 into main Nov 5, 2026
23 of 26 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-jsoncolumn-nullreference-exception branch November 5, 2026 09:06
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonColumn with primitive collection in Select throws NullReference exception

4 participants