Support ThenBy/ThenByDescending after Include/ThenInclude#80
Open
koenbeuk wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enables ThenBy/ThenByDescending to be used after EF Core Include/ThenInclude chains by (1) generating interceptors that preserve ThenBy’s required ordered-source shape via an AsOrdered adapter, and (2) adding an EF Core transformer that rewrites the resulting expression tree so ordering is applied beneath the include chain.
Changes:
- Updated interceptor generation for
ThenBy/ThenByDescendingto route the source throughExpressiveQueryableExtensions.AsOrdered<T>()instead of a direct cast. - Added an EF Core expression transformer (
RewriteThenByAfterInclude) and registered it in the EF Core options pipeline. - Added EF Core integration tests covering composed ordering after
Include/ThenIncludeand an actionable error for missing initialOrderBy.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/ExpressiveSharp.Generator.Tests/PolyfillInterceptorGenerator/SingleLambdaQueryableTests.ThenByDescending_GeneratesInterceptor.verified.txt | Updates snapshot to reflect AsOrdered usage for generated ThenByDescending interceptor source handling. |
| tests/ExpressiveSharp.Generator.Tests/PolyfillInterceptorGenerator/OrderByTests.ThenBy_CastsToIOrderedQueryable.verified.txt | Updates snapshot to reflect AsOrdered usage for generated ThenBy interceptor source handling. |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Infrastructure/IncludeTestBase.cs | Adds EF Core integration tests for ThenBy after Include/ThenInclude, plus an error-path test. |
| src/ExpressiveSharp/Extensions/ExpressiveQueryableExtensions.cs | Introduces AsOrdered<T>() and an adapter to supply an IOrderedQueryable<T>-typed expression shape to generated interceptors. |
| src/ExpressiveSharp.Generator/PolyfillInterceptorGenerator.cs | Emits AsOrdered<T>(source) for ThenBy/ThenByDescending interceptors instead of direct casts. |
| src/ExpressiveSharp.EntityFrameworkCore/Transformers/RewriteThenByAfterInclude.cs | Adds transformer that reorders the expression tree so ordering is applied under include chains (and throws an actionable error if no base ordering exists). |
| src/ExpressiveSharp.EntityFrameworkCore/Infrastructure/Internal/ExpressiveOptionsExtension.cs | Registers the new transformer in the EF Core Expressive options pipeline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _source = source; | ||
| Expression = typeof(IOrderedQueryable<T>).IsAssignableFrom(source.Expression.Type) | ||
| ? source.Expression | ||
| : Expression.Convert(source.Expression, typeof(IOrderedQueryable<T>)); |
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.
Enable the use of ThenBy and ThenByDescending methods following Include and ThenInclude calls in Entity Framework queries. This change includes a transformer that rewrites the expression tree to ensure proper ordering is applied beneath the include chain. Additionally, tests validate the functionality and error handling for these scenarios