Repository navigation
[release/10.0] Fix split query paging order when limit/offset is pushed into a subquery - #39865
Open
AndriySvyryd wants to merge 2 commits into
Open
AndriySvyryd wants to merge 2 commits into
AndriySvyryd wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The paging fix still misses subqueries behind unpaged DISTINCT wrappers, risking mismatched parents and omitted children, and the new tests bypass SQL Server configuration-based skipping.
2 open issues
What changed in this PR
Backports #39687 to EF Core 10.0 to address #39206: split queries can return missing child collections when paging with non-unique ordering is pushed into a subquery.
Changes:
- Adds identifier orderings to paged subqueries in both main and collection queries.
- Adds an AppContext switch to restore the previous behavior.
- Adds projection and Include regression tests and updates SQL Server baselines.
| File | Description |
|---|---|
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs |
Updates tracking split-query baselines with key ordering inside APPLY. |
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqlServerTest.cs |
Updates equivalent no-tracking baselines. |
test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs |
Updates paged subquery baselines with identifier orderings. |
test/EFCore.SqlServer.FunctionalTests/Query/AdHocQuerySplittingQuerySqlServerTest.cs |
Adds SQL baselines for both regression scenarios. |
test/EFCore.Relational.Specification.Tests/Query/AdHocQuerySplittingQueryTestBase.cs |
Adds sync/async tests for projection and reference Include scenarios. |
src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs |
Propagates identifier ordering into paged subqueries, guarded by a compatibility switch. |
Review effort: Balanced
artl93
approved these changes
Dec 1, 2026
artl93
left a comment
Member
There was a problem hiding this comment.
New-ish feature, 4 reports from users. Approved.
cincuranet
approved these changes
Dec 2, 2026
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 #39206
Backports #39687
Description
In EF Core 10 (#34097), split queries with
Skip/Takeand a non-uniqueOrderBywere made deterministic by appending key orderings. However, when the query also joins a reference navigation (in a projection or viaInclude), EF pushes the paging into a subquery before those key orderings are added, so they only reach the outer query. The subquery that selects the page is still ordered only by the non-unique column, so the main query and the split (collection) queries can select different rows.Customer impact
Child collections can silently come back empty (or incomplete) with no error for the above case, possibly resulting in data corruption:
Workaround: add a unique column (e.g. the key) to the ordering, e.g.
.OrderBy(x => x.Name).ThenBy(x => x.Id). This is what was recommended before EF 10, but the EF 10 docs suggest it's no longer necessary, so it's not easily discoverable.How found
4 customer reports on 10.0.x/11.0.x
Regression
No. The automatic key ordering for split queries was introduced in 10.0.0, but this case was missed.
Testing
2 new tests.
Risk
Low. Only affects split queries whose paging was pushed into a subquery. Quirk added (
Microsoft.EntityFrameworkCore.Issue39206).