Skip to content

[release/11.0] Fix FromSql queries with JSON-mapped complex properties - #39295

Merged
AndriySvyryd merged 4 commits into
release/11.0from
copilot/fix-ef-core-11-null-reference-exception
Oct 20, 2026
Merged

AndriySvyryd merged 4 commits into
release/11.0from
copilot/fix-ef-core-11-null-reference-exception

Conversation

Copilot AI commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #39251

Description
FromSql/FromSqlRaw queries on entities with JSON-mapped complex properties were failing because default-table mappings flattened JSON members and omitted the container column required by GenerateComplexJsonShaper.

Customer impact
The affected queries throw an exception. No known workaround. This isn't a common scenario, but it can be used as a workaround for other issues and unsupported features.

How found
Customer-reported on 11.0.0-rc1.

Regression
Yes, from EF Core 10.0.13

Testing
Tests added.

Risk
Low. The fix is rearranging code to also cover this case. Only FromSql queries involving JSON complex properties would be affected.

Copilot AI changed the title [WIP] Fix EF Core 11 FromSql regression for JSON complex property Fix FromSql queries with JSON-mapped complex properties Oct 16, 2026
Copilot AI requested a review from AndriySvyryd October 16, 2026 22:21
@AndriySvyryd AndriySvyryd changed the title Fix FromSql queries with JSON-mapped complex properties [release/11.0] Fix FromSql queries with JSON-mapped complex properties Oct 16, 2026
@AndriySvyryd
AndriySvyryd requested a balanced review from Copilot October 16, 2026 23:59
Comment thread .agents/skills/model-building/SKILL.md Resolved

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.

🔵 Needs a closer look

Release-branch metadata and compiled-model changes need functional and baseline test verification, which was not performed.

No open issues 🎉

What changed in this PR

Addresses #39251 by restoring FromSql materialization of JSON-mapped complex properties in EF Core 11.

Changes:

  • Creates JSON container columns recursively in default mappings.
  • Adds materialization, composed-query, and metadata regression coverage.
  • Updates compiled-model assertions, generated baseline, and mapping guidance.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Scaffolding/​Baselines/​ComplexTypes/​DbContextModelBuilder.cs Refreshes generated JSON mappings.
test/​EFCore.SqlServer.FunctionalTests/​Query/​Associations/​ComplexJson/​ComplexJsonMiscellaneousSqlServerTest.cs Verifies successful queries and SQL baselines.
test/​EFCore.Sqlite.FunctionalTests/​Query/​Associations/​ComplexJson/​ComplexJsonMiscellaneousSqliteTest.cs Verifies successful queries and SQLite SQL.
test/​EFCore.Relational.Tests/​Metadata/​RelationalModelTest.cs Tests JSON default mappings and nested metadata.
test/​EFCore.Relational.Specification.Tests/​Scaffolding/​CompiledModelRelationalTestBase.cs Scopes assertions to physical-table mappings.
test/​EFCore.Relational.Specification.Tests/​Query/​Associations/​ComplexJson/​ComplexJsonMiscellaneousRelationalTestBase.cs Adds synchronous and asynchronous composed queries.
src/​EFCore.Relational/​Metadata/​Internal/​RelationalModel.cs Creates JSON containers during recursive default mapping.
.agents/​skills/​model-building/​SKILL.md Documents recursive JSON mapping requirements.

Review effort: Balanced

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

release/11.0 2e88827 copilot/fix-ef-core-... 0ec802f +/-
76% 67% -9%
View coverage of the 10 most impacted files.
File release/11.0 2e88827 copilot/fix-ef-core-... 0ec802f +/-
/Users/runner/w...nal/Snapshot.cs 0% 60% +60%
D:\a\efcore\efc...nal\Snapshot.cs 0% 64% +64%
/home/runner/wo...nal/Snapshot.cs 0% 66% +66%
/home/runner/wo...yTypeBuilder.cs 0% 88% +88%
D:\a\efcore\efc...yTypeBuilder.cs 0% 88% +88%
/Users/runner/w...ngs.Designer.cs 0% 92% +92%
/home/runner/wo...ctExpression.cs 0% 93% +93%
D:\a\efcore\efc...ctExpression.cs 0% 93% +93%
D:\a\efcore\efc...ngs.Designer.cs 0% 94% +94%
/home/runner/wo...ngs.Designer.cs 0% 95% +95%

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

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 17, 2026 04:10
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner October 17, 2026 04:10
Copilot AI balanced review requested due to automatic review settings October 17, 2026 04:10

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

Static review found no blocking issues in the localized fix and supporting regression coverage; tests were not executed.

No open issues 🎉

Review effort: Balanced

@artl93 artl93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Regression. Customer reported. Approved.

@AndriySvyryd
AndriySvyryd merged commit 1345b92 into release/11.0 Oct 20, 2026
25 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-ef-core-11-null-reference-exception branch October 20, 2026 21:44
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.

EF Core 11 regression: FromSql on an entity with a JSON complex property throws NullReferenceException in GenerateComplexJsonShaper

5 participants