Skip to content

Support ThenBy/ThenByDescending after Include/ThenInclude#80

Open
koenbeuk wants to merge 1 commit into
mainfrom
fix/thenby-after-include
Open

Support ThenBy/ThenByDescending after Include/ThenInclude#80
koenbeuk wants to merge 1 commit into
mainfrom
fix/thenby-after-include

Conversation

@koenbeuk

Copy link
Copy Markdown
Collaborator

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

Copilot AI review requested due to automatic review settings July 26, 2026 01:24
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

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.

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/ThenByDescending to route the source through ExpressiveQueryableExtensions.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/ThenInclude and an actionable error for missing initial OrderBy.

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>));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants