Repository navigation
Synchronize IncludePaths with ownerEntity on navigation expanding - #39466
Merged
Merged
Conversation
… the include navigation expand after original ownedEntity is created Fixes dotnet#30458
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The shared tests still pass when the include is dropped and Information.Nav is null; both operator orders need non-null navigation assertions to detect the original regression.
1 open issue
What changed in this PR
Addresses #30458 by synchronizing include paths when EF Core reuses a cached owned-navigation expansion, preserving nested includes placed after Where.
Changes:
- Merges the owner’s current include paths into cached owned-navigation references.
- Adds synchronous and asynchronous tests for both
Include/Whereorders. - Adds SQL Server baselines verifying the navigation join for both orders.
| File | Description |
|---|---|
test/EFCore.SqlServer.FunctionalTests/Query/OwnedEntityQuerySqlServerTest.cs |
Adds SQL baselines for both operator orders. |
test/EFCore.Relational.Specification.Tests/Query/OwnedEntityQueryRelationalTestBase.cs |
Adds shared regression tests and a seeded owned-entity model. |
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs |
Updates include paths when reusing cached owned-navigation expansions. |
Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
AndriySvyryd
approved these changes
Oct 31, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #30458
When an owned entity contains another navigation and the
Includeclause afterWhere, the joined table is not generated because theIncludePathsof owned Entity is emptyefcore/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs
Lines 792 to 800 in 9529f69
If put the Include before
Where, the ownedEntity get its includePaths from parent OwnedEntity during the expandingof lambda bodyx.Information.Booleanfrom hereefcore/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs
Lines 174 to 177 in 9529f69
if
IncludeafterWhere, the includePath from parent owner entity is null duringWhereclause lambda expanding, hence the includePath of ownedEntity is null. To solve this, add another merge when access theownedExpansionfromForeignKeyExpansionMapefcore/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs
Lines 158 to 166 in 9529f69
Add two test cases for the different Include/Where order