Skip to content

Make JSON complex types nullable over a LEFT JOIN - #39524

Closed
jeremy-morren wants to merge 1 commit into
dotnet:mainfrom
jeremy-morren:fix-json-complex-left-join-nullability
Closed

jeremy-morren wants to merge 1 commit into
dotnet:mainfrom
jeremy-morren:fix-json-complex-left-join-nullability

Conversation

@jeremy-morren

Copy link
Copy Markdown
Contributor

Make JSON complex types nullable over a LEFT JOIN

Fixes #39523

RelationalStructuralTypeShaperExpression.MakeNullable made a table-split complex type's projection nullable (#33547) but left a JSON complex type's JsonQueryExpression as it was. Scalars bound from it stayed non-nullable, so a filter over the optional side of a LEFT JOIN got no IS NULL compensation and dropped unmatched rows. The fix also makes the JsonQueryExpression nullable, in the same way owned JSON navigations already are.

-- Before
WHERE JSON_VALUE([r0].[RequiredAssociate], '$.Int' RETURNING int) <> 8

-- After
WHERE JSON_VALUE([r0].[RequiredAssociate], '$.Int' RETURNING int) <> 8 OR JSON_VALUE([r0].[RequiredAssociate], '$.Int' RETURNING int) IS NULL

Tests: three new ComplexJsonMiscellaneousRelationalTestBase tests (left join, nested complex property, left-joined Take subquery), with SQL Server and SQLite baselines. No existing baselines changed.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 16:49
@jeremy-morren
jeremy-morren requested a review from a team as a code owner November 4, 2026 16:49

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

No active review issues are recorded for the JSON complex-type nullability fix.

No open issues 🎉

What changed in this PR

Fixes #39523 by propagating nullability to JSON complex-type expressions in EF Core’s relational query pipeline, preserving unmatched LEFT JOIN rows when filtering their scalar properties.

Changes:

  • Makes JsonQueryExpression nullable alongside table-split complex-type projections.
  • Adds regression tests for direct properties, nested properties, and left-joined Take subqueries.
  • Adds SQL Server and SQLite baselines verifying IS NULL compensation.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Query/​Associations/​ComplexJson/​ComplexJsonMiscellaneousSqlServerTest.cs Adds SQL baselines for native JSON and string-backed JSON mappings.
test/​EFCore.Sqlite.FunctionalTests/​Query/​Associations/​ComplexJson/​ComplexJsonMiscellaneousSqliteTest.cs Adds SQLite SQL baselines for all three regression scenarios.
test/​EFCore.Relational.Specification.Tests/​Query/​Associations/​ComplexJson/​ComplexJsonMiscellaneousRelationalTestBase.cs Adds shared tests checking that unmatched LEFT JOIN rows are retained.
src/​EFCore.Relational/​Query/​RelationalStructuralTypeShaperExpression.cs Propagates complex-type nullability into JSON query expressions.

Review effort: Balanced

RelationalStructuralTypeShaperExpression.MakeNullable now also marks the
JsonQueryExpression of a JSON complex type as nullable, so scalars bound
from it over the optional side of a LEFT JOIN get IS NULL compensation
and unmatched rows are no longer dropped.
@jeremy-morren
jeremy-morren force-pushed the fix-json-complex-left-join-nullability branch from f95c443 to 5f6dda1 Compare November 13, 2026 18:50
Copilot AI balanced review requested due to automatic review settings November 13, 2026 18:50

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

No active review issues block the JSON complex-type nullability fix.

No open issues 🎉

Review effort: Balanced

@jeremy-morren

Copy link
Copy Markdown
Contributor Author

Closing this PR because the commit is included in #39522

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.

Filter on JSON complex property over a LEFT JOIN drops unmatched rows

3 participants