From a260a708a51cc5ba79241c9ccc7c792e23dd017d Mon Sep 17 00:00:00 2001 From: Thomas Pakh Date: Wed, 3 Jun 2026 13:37:17 -0700 Subject: [PATCH 1/6] Fix paging failure when a query lambda contains a nested OrderBy (#8262) --- .../Expressions/ExpressionHelpers.cs | 24 +-- .../ExtractOrderPropertiesVisitor.cs | 5 + .../ReverseOrderExpressionRewriter.cs | 5 + .../Cursors/CursorKeyParser.cs | 6 + .../PagingHelperTests.cs | 158 ++++++++++++++++++ ..._Nested_OrderBy_Backward_Paging_NET10_0.md | 23 +++ ...h_Nested_OrderBy_Backward_Paging_NET8_0.md | 23 +++ ...h_Nested_OrderBy_Backward_Paging_NET9_0.md | 23 +++ ...h_Nested_OrderBy_Forward_Paging_NET10_0.md | 23 +++ ...th_Nested_OrderBy_Forward_Paging_NET8_0.md | 23 +++ ...th_Nested_OrderBy_Forward_Paging_NET9_0.md | 23 +++ ...ot_Hoist_Inner_Order_Properties_NET10_0.md | 22 +++ ...Not_Hoist_Inner_Order_Properties_NET8_0.md | 22 +++ ...Not_Hoist_Inner_Order_Properties_NET9_0.md | 22 +++ ...h_Nested_OrderBy_Forward_Paging_NET10_0.md | 22 +++ ...th_Nested_OrderBy_Forward_Paging_NET8_0.md | 22 +++ ...th_Nested_OrderBy_Forward_Paging_NET9_0.md | 22 +++ 17 files changed, 450 insertions(+), 18 deletions(-) create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET9_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET9_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET9_0.md diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs index 850860e3d8a..763d222cfe9 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs @@ -720,7 +720,6 @@ private sealed class OrderByRemovalRewriter : ExpressionVisitor { private readonly List _orderExpressions = []; private readonly List _orderMethods = []; - private bool _insideSelectProjection; public (Expression, List, List) Rewrite(Expression expression) { @@ -734,27 +733,11 @@ private sealed class OrderByRemovalRewriter : ExpressionVisitor protected override Expression VisitMethodCall(MethodCallExpression node) { - // we are not interested in nested order by calls - if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == nameof(Queryable.Select)) - { - // We first visit our parent. When we visit an expression - // like "OrderBy().Select()", we want to visit the OrderBy first. - var source = Visit(node.Arguments[0]); - - var previousState = _insideSelectProjection; - _insideSelectProjection = true; - var projection = Visit(node.Arguments[1]); - _insideSelectProjection = previousState; - - return node.Update(null, [source, projection]); - } - if (node.Method.DeclaringType == typeof(Queryable) && (node.Method.Name == nameof(Queryable.OrderBy) || node.Method.Name == nameof(Queryable.OrderByDescending) || node.Method.Name == nameof(Queryable.ThenBy) - || node.Method.Name == nameof(Queryable.ThenByDescending)) - && !_insideSelectProjection) + || node.Method.Name == nameof(Queryable.ThenByDescending))) { var lambda = (LambdaExpression)StripQuotes(node.Arguments[1]); _orderExpressions.Add(lambda); @@ -765,6 +748,11 @@ protected override Expression VisitMethodCall(MethodCallExpression node) return base.VisitMethodCall(node); } + // order operations inside lambda arguments (predicates, projections, key selectors) + // belong to their operator and are never pagination orderings, so we do not descend + // into lambda bodies. + protected override Expression VisitLambda(Expression node) => node; + private static Expression StripQuotes(Expression e) { while (e.NodeType == ExpressionType.Quote) diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs index 573f8a2b861..f8006c7dfd2 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs @@ -30,6 +30,11 @@ protected override Expression VisitMethodCall(MethodCallExpression node) return base.VisitMethodCall(node); } + // order operations inside lambda arguments (predicates, projections, key selectors) + // belong to their operator and are never pagination keys, so we do not descend into + // lambda bodies. order key lambdas are inspected explicitly via their body above. + protected override Expression VisitLambda(Expression node) => node; + protected override Expression VisitMember(MemberExpression node) { if (_isOrderScope) diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs index 09ef5c2e259..5e299115013 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs @@ -52,6 +52,11 @@ protected override Expression VisitMethodCall(MethodCallExpression node) return base.VisitMethodCall(node); } + // order operations inside lambda arguments (predicates, projections, key selectors) + // belong to their operator and must not be reversed for backward pagination, so we + // do not descend into lambda bodies. + protected override Expression VisitLambda(Expression node) => node; + public static IQueryable Rewrite(IQueryable query) { var reversedExpression = new ReverseOrderExpressionRewriter().Visit(query.Expression); diff --git a/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs b/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs index 31c04c090dd..14f1a2d1630 100644 --- a/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs +++ b/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs @@ -15,6 +15,12 @@ public sealed class CursorKeyParser : ExpressionVisitor protected override Expression VisitExtension(Expression node) => node.CanReduce ? base.VisitExtension(node) : node; + // order operations inside lambda arguments (predicates, projections, key selectors) + // belong to their operator and are never pagination keys, so we do not descend into + // lambda bodies. order key lambdas are read directly from the order method call + // arguments instead. + protected override Expression VisitLambda(Expression node) => node; + protected override Expression VisitMethodCall(MethodCallExpression node) { if (IsOrderBy(node)) diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs index 00ebccd4a97..17122e8d80b 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs @@ -312,6 +312,164 @@ await context.Brands .MatchMarkdown(); } + [Fact] + public async Task QueryContext_Selector_With_Nested_OrderBy_Forward_Paging() + { + // Arrange + using var interceptor = new CapturePagingQueryInterceptor(); + var connectionString = CreateConnectionString(); + await SeedAsync(connectionString); + + // Act + // the selector contains an OrderByDescending nested inside the projection. its + // ordering key (Product.Price) is not a member of the projected Brand type and + // must not be hoisted into the Brand selector when paging. + var query = new QueryContext( + Selector: t => new Brand { Id = t.Id, Name = t.Name }, + Sorting: new SortDefinition().AddAscending(t => t.Id)); + + query = query.Select(t => new Brand + { + DisplayName = t.Products + .OrderByDescending(p => p.Price) + .ThenBy(p => p.AvailableStock) + .FirstOrDefault()!.Name + }); + + var arguments = new PagingArguments(first: 2); + + await using var context = new CatalogContext(connectionString); + + var page = await context.Brands + .With(query) + .ToPageAsync(arguments); + + // a cursor must be creatable for each edge. this evaluates the cursor keys against + // the projected Brand, which fails if a nested projection order key was collected. + page.CreateCursor(page.First!.Value); + + // Assert + Snapshot + .Create(postFix: TestEnvironment.TargetFramework) + .AddQueries(interceptor.Queries) + .MatchMarkdown(); + } + + [Fact] + public async Task QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties() + { + // Arrange + using var interceptor = new CapturePagingQueryInterceptor(); + var connectionString = CreateConnectionString(); + await SeedAsync(connectionString); + + // Act + // the selector contains an OrderByDescending nested inside the projection. its + // ordering key (Product.Price) is not a member of the projected Brand type and + // must not be hoisted into the Brand selector when paging. + var query = new QueryContext( + Selector: t => new Brand { Id = t.Id, Name = t.Name }, + Sorting: new SortDefinition().AddDescending(t => t.Id)); + + query = query.Select(t => new Brand + { + DisplayName = t.Products + .OrderByDescending(p => p.Price) + .ThenBy(p => p.AvailableStock) + .FirstOrDefault()!.Name + }); + + var arguments = new PagingArguments(last: 2); + + await using var context = new CatalogContext(connectionString); + + var page = await context.Brands + .With(query) + .ToPageAsync(arguments); + + // a cursor must be creatable for each edge. this evaluates the cursor keys against + // the projected Brand, which fails if a nested projection order key was collected. + page.CreateCursor(page.First!.Value); + + // Assert + Snapshot + .Create(postFix: TestEnvironment.TargetFramework) + .AddQueries(interceptor.Queries) + .MatchMarkdown(); + } + + [Fact] + public async Task QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging() + { + // Arrange + using var interceptor = new CapturePagingQueryInterceptor(); + var connectionString = CreateConnectionString(); + await SeedAsync(connectionString); + + // Act + // the predicate contains an OrderByDescending nested inside the Where lambda. its + // ordering key (Product.Price) is not a pagination key and must not be hoisted + // into the Brand selector or collected as a cursor key. + var query = new QueryContext( + Selector: t => new Brand { Id = t.Id, Name = t.Name }, + Predicate: t => t.Products.OrderByDescending(p => p.Price).FirstOrDefault()!.Price >= 0m, + Sorting: new SortDefinition().AddAscending(t => t.Id)); + + var arguments = new PagingArguments(first: 2); + + await using var context = new CatalogContext(connectionString); + + var page = await context.Brands + .With(query) + .ToPageAsync(arguments); + + // a cursor must be creatable for each edge. this evaluates the cursor keys against + // the projected Brand, which fails if the predicate's nested order key was collected. + page.CreateCursor(page.First!.Value); + + // Assert + Snapshot + .Create(postFix: TestEnvironment.TargetFramework) + .AddQueries(interceptor.Queries) + .MatchMarkdown(); + } + + [Fact] + public async Task QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging() + { + // Arrange + using var interceptor = new CapturePagingQueryInterceptor(); + var connectionString = CreateConnectionString(); + await SeedAsync(connectionString); + + // Act + // the predicate contains an OrderByDescending nested inside the Where lambda. + // backward paging reverses the top-level ordering and must not touch or reverse + // the order operations inside the predicate. + var query = new QueryContext( + Selector: t => new Brand { Id = t.Id, Name = t.Name }, + Predicate: t => t.Products.OrderByDescending(p => p.Price).FirstOrDefault()!.Price >= 0m, + Sorting: new SortDefinition().AddDescending(t => t.Id)); + + var arguments = new PagingArguments(last: 2); + + await using var context = new CatalogContext(connectionString); + + var page = await context.Brands + .With(query) + .ToPageAsync(arguments); + + // a cursor must be creatable for each edge. this evaluates the cursor keys against + // the projected Brand, which fails if the predicate's nested order key was collected. + page.CreateCursor(page.First!.Value); + + // Assert + Snapshot + .Create(postFix: TestEnvironment.TargetFramework) + .AddQueries(interceptor.Queries) + .MatchMarkdown(); + } + [Fact] public async Task Fetch_Last_2_Items_Before_Last_Page() { diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET10_0.md new file mode 100644 index 00000000000..7b941f49038 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET10_0.md @@ -0,0 +1,23 @@ +# QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging + +## SQL 0 + +```sql +-- @p='3' +SELECT b."Id", b."Name" +FROM "Brands" AS b +WHERE ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC + LIMIT 1) >= 0.0 +ORDER BY b."Id" +LIMIT @p +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => (t.Products.OrderByDescending(p => p.Price).FirstOrDefault().Price >= 0)).OrderBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET8_0.md new file mode 100644 index 00000000000..a166ad01f46 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET8_0.md @@ -0,0 +1,23 @@ +# QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b."Id", b."Name" +FROM "Brands" AS b +WHERE ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC + LIMIT 1) >= 0.0 +ORDER BY b."Id" +LIMIT @__p_0 +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => (t.Products.OrderByDescending(p => p.Price).FirstOrDefault().Price >= 0)).OrderBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET9_0.md new file mode 100644 index 00000000000..a166ad01f46 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET9_0.md @@ -0,0 +1,23 @@ +# QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b."Id", b."Name" +FROM "Brands" AS b +WHERE ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC + LIMIT 1) >= 0.0 +ORDER BY b."Id" +LIMIT @__p_0 +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => (t.Products.OrderByDescending(p => p.Price).FirstOrDefault().Price >= 0)).OrderBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET10_0.md new file mode 100644 index 00000000000..92c7d901acb --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET10_0.md @@ -0,0 +1,23 @@ +# QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @p='3' +SELECT b."Id", b."Name" +FROM "Brands" AS b +WHERE ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC + LIMIT 1) >= 0.0 +ORDER BY b."Id" +LIMIT @p +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => (t.Products.OrderByDescending(p => p.Price).FirstOrDefault().Price >= 0)).OrderBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET8_0.md new file mode 100644 index 00000000000..68a57bb7683 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET8_0.md @@ -0,0 +1,23 @@ +# QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b."Id", b."Name" +FROM "Brands" AS b +WHERE ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC + LIMIT 1) >= 0.0 +ORDER BY b."Id" +LIMIT @__p_0 +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => (t.Products.OrderByDescending(p => p.Price).FirstOrDefault().Price >= 0)).OrderBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET9_0.md new file mode 100644 index 00000000000..68a57bb7683 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET9_0.md @@ -0,0 +1,23 @@ +# QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b."Id", b."Name" +FROM "Brands" AS b +WHERE ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC + LIMIT 1) >= 0.0 +ORDER BY b."Id" +LIMIT @__p_0 +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => (t.Products.OrderByDescending(p => p.Price).FirstOrDefault().Price >= 0)).OrderBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md new file mode 100644 index 00000000000..2e7eead13be --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md @@ -0,0 +1,22 @@ +# QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties + +## SQL 0 + +```sql +-- @p='3' +SELECT b."Id", b."Name", ( + SELECT p."Name" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC, p."AvailableStock" + LIMIT 1) AS "DisplayName" +FROM "Brands" AS b +ORDER BY b."Id" +LIMIT @p +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md new file mode 100644 index 00000000000..7a4618cad28 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md @@ -0,0 +1,22 @@ +# QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b."Id", b."Name", ( + SELECT p."Name" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC, p."AvailableStock" + LIMIT 1) AS "DisplayName" +FROM "Brands" AS b +ORDER BY b."Id" +LIMIT @__p_0 +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md new file mode 100644 index 00000000000..7a4618cad28 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md @@ -0,0 +1,22 @@ +# QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b."Id", b."Name", ( + SELECT p."Name" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC, p."AvailableStock" + LIMIT 1) AS "DisplayName" +FROM "Brands" AS b +ORDER BY b."Id" +LIMIT @__p_0 +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET10_0.md new file mode 100644 index 00000000000..a1bf9c2e363 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET10_0.md @@ -0,0 +1,22 @@ +# QueryContext_Selector_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @p='3' +SELECT b."Id", b."Name", ( + SELECT p."Name" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC, p."AvailableStock" + LIMIT 1) AS "DisplayName" +FROM "Brands" AS b +ORDER BY b."Id" +LIMIT @p +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET8_0.md new file mode 100644 index 00000000000..08a8d64a9a5 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET8_0.md @@ -0,0 +1,22 @@ +# QueryContext_Selector_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b."Id", b."Name", ( + SELECT p."Name" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC, p."AvailableStock" + LIMIT 1) AS "DisplayName" +FROM "Brands" AS b +ORDER BY b."Id" +LIMIT @__p_0 +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET9_0.md new file mode 100644 index 00000000000..08a8d64a9a5 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET9_0.md @@ -0,0 +1,22 @@ +# QueryContext_Selector_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b."Id", b."Name", ( + SELECT p."Name" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC, p."AvailableStock" + LIMIT 1) AS "DisplayName" +FROM "Brands" AS b +ORDER BY b."Id" +LIMIT @__p_0 +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +``` From 62e98de5c69aca84141e703283e425c9585e4371 Mon Sep 17 00:00:00 2001 From: Thomas Pakh Date: Wed, 3 Jun 2026 13:53:52 -0700 Subject: [PATCH 2/6] Share the lambda-skip invariant via a QueryChainVisitor base class --- .../Expressions/ExpressionHelpers.cs | 7 +------ .../ExtractOrderPropertiesVisitor.cs | 7 +------ .../ReverseOrderExpressionRewriter.cs | 7 +------ .../Cursors/CursorKeyParser.cs | 9 ++------- .../Expressions/QueryChainVisitor.cs | 19 +++++++++++++++++++ 5 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 src/GreenDonut/src/GreenDonut.Data/Expressions/QueryChainVisitor.cs diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs index 763d222cfe9..11bfdfd215f 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs @@ -716,7 +716,7 @@ public readonly struct OrderRewriterResult( public ReadOnlySpan OrderMethods => CollectionsMarshal.AsSpan(orderMethods); } - private sealed class OrderByRemovalRewriter : ExpressionVisitor + private sealed class OrderByRemovalRewriter : QueryChainVisitor { private readonly List _orderExpressions = []; private readonly List _orderMethods = []; @@ -748,11 +748,6 @@ protected override Expression VisitMethodCall(MethodCallExpression node) return base.VisitMethodCall(node); } - // order operations inside lambda arguments (predicates, projections, key selectors) - // belong to their operator and are never pagination orderings, so we do not descend - // into lambda bodies. - protected override Expression VisitLambda(Expression node) => node; - private static Expression StripQuotes(Expression e) { while (e.NodeType == ExpressionType.Quote) diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs index f8006c7dfd2..e3af4a66324 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs @@ -2,7 +2,7 @@ namespace GreenDonut.Data.Expressions; -internal sealed class ExtractOrderPropertiesVisitor : ExpressionVisitor +internal sealed class ExtractOrderPropertiesVisitor : QueryChainVisitor { private const string OrderByMethod = "OrderBy"; private const string ThenByMethod = "ThenBy"; @@ -30,11 +30,6 @@ protected override Expression VisitMethodCall(MethodCallExpression node) return base.VisitMethodCall(node); } - // order operations inside lambda arguments (predicates, projections, key selectors) - // belong to their operator and are never pagination keys, so we do not descend into - // lambda bodies. order key lambdas are inspected explicitly via their body above. - protected override Expression VisitLambda(Expression node) => node; - protected override Expression VisitMember(MemberExpression node) { if (_isOrderScope) diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs index 5e299115013..869e21839fe 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs @@ -3,7 +3,7 @@ namespace GreenDonut.Data.Expressions; -public class ReverseOrderExpressionRewriter : ExpressionVisitor +public class ReverseOrderExpressionRewriter : QueryChainVisitor { private static readonly MethodInfo s_orderByMethod = typeof(Queryable).GetMethods() .First(m => m.Name == nameof(Queryable.OrderBy) && m.GetParameters().Length == 2); @@ -52,11 +52,6 @@ protected override Expression VisitMethodCall(MethodCallExpression node) return base.VisitMethodCall(node); } - // order operations inside lambda arguments (predicates, projections, key selectors) - // belong to their operator and must not be reversed for backward pagination, so we - // do not descend into lambda bodies. - protected override Expression VisitLambda(Expression node) => node; - public static IQueryable Rewrite(IQueryable query) { var reversedExpression = new ReverseOrderExpressionRewriter().Visit(query.Expression); diff --git a/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs b/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs index 14f1a2d1630..bdd558a6c11 100644 --- a/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs +++ b/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs @@ -1,12 +1,13 @@ using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; +using GreenDonut.Data.Expressions; namespace GreenDonut.Data.Cursors; /// /// This expression visitor will collect the cursor keys from a query expression. /// -public sealed class CursorKeyParser : ExpressionVisitor +public sealed class CursorKeyParser : QueryChainVisitor { private readonly List _keys = []; @@ -15,12 +16,6 @@ public sealed class CursorKeyParser : ExpressionVisitor protected override Expression VisitExtension(Expression node) => node.CanReduce ? base.VisitExtension(node) : node; - // order operations inside lambda arguments (predicates, projections, key selectors) - // belong to their operator and are never pagination keys, so we do not descend into - // lambda bodies. order key lambdas are read directly from the order method call - // arguments instead. - protected override Expression VisitLambda(Expression node) => node; - protected override Expression VisitMethodCall(MethodCallExpression node) { if (IsOrderBy(node)) diff --git a/src/GreenDonut/src/GreenDonut.Data/Expressions/QueryChainVisitor.cs b/src/GreenDonut/src/GreenDonut.Data/Expressions/QueryChainVisitor.cs new file mode 100644 index 00000000000..6fe51c66da9 --- /dev/null +++ b/src/GreenDonut/src/GreenDonut.Data/Expressions/QueryChainVisitor.cs @@ -0,0 +1,19 @@ +using System.Linq.Expressions; + +namespace GreenDonut.Data.Expressions; + +/// +/// A base class for expression visitors that inspect or rewrite the top-level +/// method chain of a query. Order operations that are relevant for pagination +/// only appear on this chain. Lambda arguments (predicates, projections, key +/// selectors) belong to their operator and are not traversed automatically; +/// a visitor that needs an order key lambda inspects it explicitly. +/// +public abstract class QueryChainVisitor : ExpressionVisitor +{ + /// + /// Returns the lambda unchanged so that lambda bodies are excluded from the + /// traversal. + /// + protected sealed override Expression VisitLambda(Expression node) => node; +} From f59311777dacdea80767233533127f860ab334fb Mon Sep 17 00:00:00 2001 From: Thomas Pakh Date: Wed, 3 Jun 2026 14:54:15 -0700 Subject: [PATCH 3/6] Fix paging when an order key contains a nested OrderBy --- .../ExtractOrderPropertiesVisitor.cs | 24 +++--- .../PagingHelperTests.cs | 70 +++++++++++++++++ ...h_Nested_OrderBy_Forward_Paging_NET10_0.md | 32 ++++++++ ...th_Nested_OrderBy_Forward_Paging_NET8_0.md | 32 ++++++++ ...th_Nested_OrderBy_Forward_Paging_NET9_0.md | 32 ++++++++ ...With_Nested_OrderBy_Second_Page_NET10_0.md | 76 +++++++++++++++++++ ..._With_Nested_OrderBy_Second_Page_NET8_0.md | 76 +++++++++++++++++++ ..._With_Nested_OrderBy_Second_Page_NET9_0.md | 76 +++++++++++++++++++ 8 files changed, 407 insertions(+), 11 deletions(-) create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET9_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET9_0.md diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs index e3af4a66324..e620e36c1ae 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs @@ -8,23 +8,23 @@ internal sealed class ExtractOrderPropertiesVisitor : QueryChainVisitor private const string ThenByMethod = "ThenBy"; private const string OrderByDescendingMethod = "OrderByDescending"; private const string ThenByDescendingMethod = "ThenByDescending"; - private bool _isOrderScope; + private ParameterExpression? _orderKeyParameter; public List OrderProperties { get; } = []; protected override Expression VisitMethodCall(MethodCallExpression node) { - if (node.Method.Name == OrderByMethod - || node.Method.Name == ThenByMethod - || node.Method.Name == OrderByDescendingMethod - || node.Method.Name == ThenByDescendingMethod) + if (_orderKeyParameter is null + && (node.Method.Name == OrderByMethod + || node.Method.Name == ThenByMethod + || node.Method.Name == OrderByDescendingMethod + || node.Method.Name == ThenByDescendingMethod)) { - _isOrderScope = true; - var lambda = StripQuotes(node.Arguments[1]); - Visit(lambda.Body); - _isOrderScope = false; + _orderKeyParameter = lambda.Parameters[0]; + Visit(lambda.Body); + _orderKeyParameter = null; } return base.VisitMethodCall(node); @@ -32,9 +32,11 @@ protected override Expression VisitMethodCall(MethodCallExpression node) protected override Expression VisitMember(MemberExpression node) { - if (_isOrderScope) + // an order key is a lambda. we only collect members rooted at that lambda's own + // parameter; members rooted on nested lambdas or intermediate results cannot be + // hoisted into the selector. + if (_orderKeyParameter is not null && node.Expression == _orderKeyParameter) { - // we only collect members that are within an order method. OrderProperties.Add(node); } diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs index 17122e8d80b..28da78d0b2e 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs @@ -470,6 +470,76 @@ public async Task QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging() .MatchMarkdown(); } + [Fact] + public async Task QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging() + { + // Arrange + using var interceptor = new CapturePagingQueryInterceptor(); + var connectionString = CreateConnectionString(); + await SeedAsync(connectionString); + + // Act + // the sort key itself orders a child collection. the key's root member + // (Brand.Products) must be hoisted into the selector so cursors can be + // created, while the inner key (Product.Price) must not be. + var query = new QueryContext( + Selector: t => new Brand { Id = t.Id, Name = t.Name }, + Sorting: new SortDefinition() + .AddAscending(t => t.Products.OrderBy(p => p.Price).First().Price) + .AddAscending(t => t.Id)); + + var arguments = new PagingArguments(first: 2); + + await using var context = new CatalogContext(connectionString); + + var page = await context.Brands + .With(query) + .ToPageAsync(arguments); + + // a cursor must be creatable for each edge. this evaluates the computed + // order key against the projected Brand and requires Products to be loaded. + page.CreateCursor(page.First!.Value); + + // Assert + Snapshot + .Create(postFix: TestEnvironment.TargetFramework) + .AddQueries(interceptor.Queries) + .MatchMarkdown(); + } + + [Fact] + public async Task QueryContext_OrderKey_With_Nested_OrderBy_Second_Page() + { + // Arrange + using var interceptor = new CapturePagingQueryInterceptor(); + var connectionString = CreateConnectionString(); + await SeedAsync(connectionString); + + var query = new QueryContext( + Selector: t => new Brand { Id = t.Id, Name = t.Name }, + Sorting: new SortDefinition() + .AddAscending(t => t.Products.OrderBy(p => p.Price).First().Price) + .AddAscending(t => t.Id)); + + await using var context = new CatalogContext(connectionString); + + // -> get first page + var arguments = new PagingArguments(first: 2); + var page = await context.Brands.With(query).ToPageAsync(arguments); + + // Act + // paging to the second page builds a keyset predicate from the computed + // order key, which must translate to SQL. + arguments = new PagingArguments(first: 2, after: page.CreateEndCursor()); + page = await context.Brands.With(query).ToPageAsync(arguments); + + // Assert + Snapshot + .Create(postFix: TestEnvironment.TargetFramework) + .AddQueries(interceptor.Queries) + .MatchMarkdown(); + } + [Fact] public async Task Fetch_Last_2_Items_Before_Last_Page() { diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET10_0.md new file mode 100644 index 00000000000..d25a8af60d0 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET10_0.md @@ -0,0 +1,32 @@ +# QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @p='3' +SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET8_0.md new file mode 100644 index 00000000000..ae8cb27dbf1 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET8_0.md @@ -0,0 +1,32 @@ +# QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT t."Id", t."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_0 +) AS t +LEFT JOIN "Products" AS p0 ON t."Id" = p0."BrandId" +ORDER BY t.c, t."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET9_0.md new file mode 100644 index 00000000000..624616b8d1d --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET9_0.md @@ -0,0 +1,32 @@ +# QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_0 +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET10_0.md new file mode 100644 index 00000000000..02bb7f257c3 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET10_0.md @@ -0,0 +1,76 @@ +# QueryContext_OrderKey_With_Nested_OrderBy_Second_Page + +## SQL 0 + +```sql +-- @p='3' +SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) +``` + +## SQL 1 + +```sql +-- @value='0' +-- @value1='2' +-- @p='3' +SELECT b0."Id", b0."Name", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + WHERE ( + SELECT p0."Price" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" + ORDER BY p0."Price" + LIMIT 1) > @value OR (( + SELECT p1."Price" + FROM "Products" AS p1 + WHERE b."Id" = p1."BrandId" + ORDER BY p1."Price" + LIMIT 1) = @value AND b."Id" > @value1) + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 1 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET8_0.md new file mode 100644 index 00000000000..be06e5ec9b5 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET8_0.md @@ -0,0 +1,76 @@ +# QueryContext_OrderKey_With_Nested_OrderBy_Second_Page + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT t."Id", t."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_0 +) AS t +LEFT JOIN "Products" AS p0 ON t."Id" = p0."BrandId" +ORDER BY t.c, t."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) +``` + +## SQL 1 + +```sql +-- @__value_0='0' +-- @__value_1='2' +-- @__p_2='3' +SELECT t."Id", t."Name", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + WHERE ( + SELECT p0."Price" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" + ORDER BY p0."Price" + LIMIT 1) > @__value_0 OR (( + SELECT p1."Price" + FROM "Products" AS p1 + WHERE b."Id" = p1."BrandId" + ORDER BY p1."Price" + LIMIT 1) = @__value_0 AND b."Id" > @__value_1) + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_2 +) AS t +LEFT JOIN "Products" AS p2 ON t."Id" = p2."BrandId" +ORDER BY t.c, t."Id" +``` + +## Expression 1 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET9_0.md new file mode 100644 index 00000000000..60694b56eac --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET9_0.md @@ -0,0 +1,76 @@ +# QueryContext_OrderKey_With_Nested_OrderBy_Second_Page + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_0 +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) +``` + +## SQL 1 + +```sql +-- @__value_0='0' +-- @__value_1='2' +-- @__p_2='3' +SELECT b0."Id", b0."Name", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + WHERE ( + SELECT p0."Price" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" + ORDER BY p0."Price" + LIMIT 1) > @__value_0 OR (( + SELECT p1."Price" + FROM "Products" AS p1 + WHERE b."Id" = p1."BrandId" + ORDER BY p1."Price" + LIMIT 1) = @__value_0 AND b."Id" > @__value_1) + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_2 +) AS b0 +LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 1 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}) +``` From 8b7dcec1b45c610946f5414f318bdf4b33076ca9 Mon Sep 17 00:00:00 2001 From: Thomas Pakh Date: Thu, 9 Jul 2026 18:39:26 -0700 Subject: [PATCH 4/6] Adapt nested-OrderBy paging tests to xUnit v3 and add net11 snapshots --- .../PagingHelperTests.cs | 14 ++-- ...h_Nested_OrderBy_Forward_Paging_NET11_0.md | 32 ++++++++ ...With_Nested_OrderBy_Second_Page_NET11_0.md | 76 +++++++++++++++++++ ..._Nested_OrderBy_Backward_Paging_NET11_0.md | 23 ++++++ ...h_Nested_OrderBy_Forward_Paging_NET11_0.md | 23 ++++++ ...ot_Hoist_Inner_Order_Properties_NET11_0.md | 22 ++++++ ...h_Nested_OrderBy_Forward_Paging_NET11_0.md | 22 ++++++ 7 files changed, 205 insertions(+), 7 deletions(-) create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET11_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET11_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET11_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET11_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET11_0.md diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs index c65775ffba0..5ce0fa92926 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs @@ -364,7 +364,7 @@ public async Task QueryContext_Selector_With_Nested_OrderBy_Forward_Paging() var page = await context.Brands .With(query) - .ToPageAsync(arguments); + .ToPageAsync(arguments, Xunit.TestContext.Current.CancellationToken); // a cursor must be creatable for each edge. this evaluates the cursor keys against // the projected Brand, which fails if a nested projection order key was collected. @@ -407,7 +407,7 @@ public async Task QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner var page = await context.Brands .With(query) - .ToPageAsync(arguments); + .ToPageAsync(arguments, Xunit.TestContext.Current.CancellationToken); // a cursor must be creatable for each edge. this evaluates the cursor keys against // the projected Brand, which fails if a nested projection order key was collected. @@ -443,7 +443,7 @@ public async Task QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging() var page = await context.Brands .With(query) - .ToPageAsync(arguments); + .ToPageAsync(arguments, Xunit.TestContext.Current.CancellationToken); // a cursor must be creatable for each edge. this evaluates the cursor keys against // the projected Brand, which fails if the predicate's nested order key was collected. @@ -479,7 +479,7 @@ public async Task QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging() var page = await context.Brands .With(query) - .ToPageAsync(arguments); + .ToPageAsync(arguments, Xunit.TestContext.Current.CancellationToken); // a cursor must be creatable for each edge. this evaluates the cursor keys against // the projected Brand, which fails if the predicate's nested order key was collected. @@ -516,7 +516,7 @@ public async Task QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging() var page = await context.Brands .With(query) - .ToPageAsync(arguments); + .ToPageAsync(arguments, Xunit.TestContext.Current.CancellationToken); // a cursor must be creatable for each edge. this evaluates the computed // order key against the projected Brand and requires Products to be loaded. @@ -547,13 +547,13 @@ public async Task QueryContext_OrderKey_With_Nested_OrderBy_Second_Page() // -> get first page var arguments = new PagingArguments(first: 2); - var page = await context.Brands.With(query).ToPageAsync(arguments); + var page = await context.Brands.With(query).ToPageAsync(arguments, Xunit.TestContext.Current.CancellationToken); // Act // paging to the second page builds a keyset predicate from the computed // order key, which must translate to SQL. arguments = new PagingArguments(first: 2, after: page.CreateEndCursor()); - page = await context.Brands.With(query).ToPageAsync(arguments); + page = await context.Brands.With(query).ToPageAsync(arguments, Xunit.TestContext.Current.CancellationToken); // Assert Snapshot diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET11_0.md new file mode 100644 index 00000000000..d25a8af60d0 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET11_0.md @@ -0,0 +1,32 @@ +# QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @p='3' +SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET11_0.md new file mode 100644 index 00000000000..f0114ca1043 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET11_0.md @@ -0,0 +1,76 @@ +# QueryContext_OrderKey_With_Nested_OrderBy_Second_Page + +## SQL 0 + +```sql +-- @p='3' +SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) +``` + +## SQL 1 + +```sql +-- @value='0' +-- @value2='2' +-- @p='3' +SELECT b0."Id", b0."Name", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + WHERE ( + SELECT p0."Price" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" + ORDER BY p0."Price" + LIMIT 1) > @value OR (( + SELECT p1."Price" + FROM "Products" AS p1 + WHERE b."Id" = p1."BrandId" + ORDER BY p1."Price" + LIMIT 1) = @value AND b."Id" > @value2) + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 1 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET11_0.md new file mode 100644 index 00000000000..7b941f49038 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET11_0.md @@ -0,0 +1,23 @@ +# QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging + +## SQL 0 + +```sql +-- @p='3' +SELECT b."Id", b."Name" +FROM "Brands" AS b +WHERE ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC + LIMIT 1) >= 0.0 +ORDER BY b."Id" +LIMIT @p +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => (t.Products.OrderByDescending(p => p.Price).FirstOrDefault().Price >= 0)).OrderBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET11_0.md new file mode 100644 index 00000000000..92c7d901acb --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET11_0.md @@ -0,0 +1,23 @@ +# QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @p='3' +SELECT b."Id", b."Name" +FROM "Brands" AS b +WHERE ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC + LIMIT 1) >= 0.0 +ORDER BY b."Id" +LIMIT @p +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => (t.Products.OrderByDescending(p => p.Price).FirstOrDefault().Price >= 0)).OrderBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md new file mode 100644 index 00000000000..2e7eead13be --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md @@ -0,0 +1,22 @@ +# QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties + +## SQL 0 + +```sql +-- @p='3' +SELECT b."Id", b."Name", ( + SELECT p."Name" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC, p."AvailableStock" + LIMIT 1) AS "DisplayName" +FROM "Brands" AS b +ORDER BY b."Id" +LIMIT @p +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET11_0.md new file mode 100644 index 00000000000..a1bf9c2e363 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET11_0.md @@ -0,0 +1,22 @@ +# QueryContext_Selector_With_Nested_OrderBy_Forward_Paging + +## SQL 0 + +```sql +-- @p='3' +SELECT b."Id", b."Name", ( + SELECT p."Name" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" + ORDER BY p."Price" DESC, p."AvailableStock" + LIMIT 1) AS "DisplayName" +FROM "Brands" AS b +ORDER BY b."Id" +LIMIT @p +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +``` From 8739ea99b2bcbbc409fe9015b88e43fb62cdfca7 Mon Sep 17 00:00:00 2001 From: Thomas Pakh Date: Fri, 10 Jul 2026 10:38:09 -0700 Subject: [PATCH 5/6] Strengthen nested-OrderBy selector test and document computed-key null limitation --- .../Expressions/ExpressionHelpers.cs | 12 ++++++++++-- .../PagingHelperTests.cs | 2 +- ..._Does_Not_Hoist_Inner_Order_Properties_NET10_0.md | 4 ++-- ..._Does_Not_Hoist_Inner_Order_Properties_NET11_0.md | 4 ++-- ...y_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md | 4 ++-- ...y_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md | 4 ++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs index a0b369787f1..fc5a7373cb0 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs @@ -343,8 +343,16 @@ private static bool IsNullable(LambdaExpression expression) } // For computed key expressions (method calls, concatenation, etc.) we cannot inspect - // NRT annotations at runtime. Treat as non-nullable — the safe default that avoids - // injecting spurious null-handling into the generated WHERE clause. + // NRT annotations at runtime, so they are treated as non-nullable and no null + // handling is emitted into the generated WHERE clause. + // + // Known limitation: a computed key that can actually yield null (for example + // t.Products.OrderBy(p => p.Price).First().Price over a possibly-empty child + // collection) is not covered. Such a row sorts to the NULL end and is then silently + // dropped from later keyset pages, because its SQL comparisons evaluate to UNKNOWN, + // and building a cursor over a First() key throws on the empty collection. The + // navigation-path nullability handling added in #9955 does not extend to computed + // keys; supporting them is deferred to a follow-up. return false; } diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs index 5ce0fa92926..71dedcc6325 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs @@ -391,7 +391,7 @@ public async Task QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner // must not be hoisted into the Brand selector when paging. var query = new QueryContext( Selector: t => new Brand { Id = t.Id, Name = t.Name }, - Sorting: new SortDefinition().AddDescending(t => t.Id)); + Sorting: new SortDefinition().AddAscending(t => t.Id)); query = query.Select(t => new Brand { diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md index 2e7eead13be..d65b3ecc735 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md @@ -11,12 +11,12 @@ SELECT b."Id", b."Name", ( ORDER BY p."Price" DESC, p."AvailableStock" LIMIT 1) AS "DisplayName" FROM "Brands" AS b -ORDER BY b."Id" +ORDER BY b."Id" DESC LIMIT @p ``` ## Expression 0 ```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderByDescending(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) ``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md index 2e7eead13be..d65b3ecc735 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md @@ -11,12 +11,12 @@ SELECT b."Id", b."Name", ( ORDER BY p."Price" DESC, p."AvailableStock" LIMIT 1) AS "DisplayName" FROM "Brands" AS b -ORDER BY b."Id" +ORDER BY b."Id" DESC LIMIT @p ``` ## Expression 0 ```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderByDescending(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) ``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md index 7a4618cad28..ab78acac87f 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md @@ -11,12 +11,12 @@ SELECT b."Id", b."Name", ( ORDER BY p."Price" DESC, p."AvailableStock" LIMIT 1) AS "DisplayName" FROM "Brands" AS b -ORDER BY b."Id" +ORDER BY b."Id" DESC LIMIT @__p_0 ``` ## Expression 0 ```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderByDescending(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) ``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md index 7a4618cad28..ab78acac87f 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md @@ -11,12 +11,12 @@ SELECT b."Id", b."Name", ( ORDER BY p."Price" DESC, p."AvailableStock" LIMIT 1) AS "DisplayName" FROM "Brands" AS b -ORDER BY b."Id" +ORDER BY b."Id" DESC LIMIT @__p_0 ``` ## Expression 0 ```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderByDescending(t => t.Id).Select(root => new Brand() {Id = root.Id, Name = root.Name, DisplayName = root.Products.OrderByDescending(p => p.Price).ThenBy(p => p.AvailableStock).FirstOrDefault().Name}).Take(3) ``` From cd3033f2d7ed24ce5e121338e1a8cead4acaa116 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Fri, 10 Jul 2026 23:06:36 +0200 Subject: [PATCH 6/6] Strengthen nested OrderBy paging fix --- .../Expressions/ExpressionHelpers.cs | 16 +-- .../ExtractOrderPropertiesVisitor.cs | 39 ++++---- .../ReverseOrderExpressionRewriter.cs | 4 +- .../Cursors/CursorKeyParser.cs | 5 +- .../Expressions/QueryChainVisitor.cs | 19 ---- .../PagingHelperIntegrationTests.cs | 45 +++++++++ .../PagingHelperTests.cs | 35 ++++--- ...g_When_PredicateContainsOrderBy_NET10_0.md | 98 +++++++++++++++++++ ...g_When_PredicateContainsOrderBy_NET11_0.md | 98 +++++++++++++++++++ ...ng_When_PredicateContainsOrderBy_NET8_0.md | 98 +++++++++++++++++++ ...ng_When_PredicateContainsOrderBy_NET9_0.md | 98 +++++++++++++++++++ ...h_Nested_OrderBy_Forward_Paging_NET10_0.md | 32 ------ ...h_Nested_OrderBy_Forward_Paging_NET11_0.md | 32 ------ ...th_Nested_OrderBy_Forward_Paging_NET8_0.md | 32 ------ ...th_Nested_OrderBy_Forward_Paging_NET9_0.md | 32 ------ ...With_Nested_OrderBy_Second_Page_NET10_0.md | 76 -------------- ...With_Nested_OrderBy_Second_Page_NET11_0.md | 76 -------------- ..._With_Nested_OrderBy_Second_Page_NET8_0.md | 76 -------------- ..._With_Nested_OrderBy_Second_Page_NET9_0.md | 76 -------------- ...n_OrderKeyContainsNestedOrderBy_NET10_0.md | 32 ++++++ ...n_OrderKeyContainsNestedOrderBy_NET11_0.md | 32 ++++++ ...en_OrderKeyContainsNestedOrderBy_NET8_0.md | 32 ++++++ ...en_OrderKeyContainsNestedOrderBy_NET9_0.md | 32 ++++++ ...PredicateContainsNestedOrderBy_NET10_0.md} | 2 +- ...PredicateContainsNestedOrderBy_NET11_0.md} | 2 +- ..._PredicateContainsNestedOrderBy_NET8_0.md} | 2 +- ..._PredicateContainsNestedOrderBy_NET9_0.md} | 2 +- ..._SelectorContainsNestedOrderBy_NET10_0.md} | 2 +- ..._SelectorContainsNestedOrderBy_NET11_0.md} | 2 +- ...n_SelectorContainsNestedOrderBy_NET8_0.md} | 2 +- ...n_SelectorContainsNestedOrderBy_NET9_0.md} | 2 +- ...n_OrderKeyContainsNestedOrderBy_NET10_0.md | 85 ++++++++++++++++ ...n_OrderKeyContainsNestedOrderBy_NET11_0.md | 85 ++++++++++++++++ ...en_OrderKeyContainsNestedOrderBy_NET8_0.md | 85 ++++++++++++++++ ...en_OrderKeyContainsNestedOrderBy_NET9_0.md | 85 ++++++++++++++++ ...gSelectorContainsNestedOrderBy_NET10_0.md} | 2 +- ...gSelectorContainsNestedOrderBy_NET11_0.md} | 2 +- ...ngSelectorContainsNestedOrderBy_NET8_0.md} | 2 +- ...ngSelectorContainsNestedOrderBy_NET9_0.md} | 2 +- ...PagingPredicateContainsOrderBy_NET10_0.md} | 2 +- ...PagingPredicateContainsOrderBy_NET11_0.md} | 2 +- ...dPagingPredicateContainsOrderBy_NET8_0.md} | 2 +- ...dPagingPredicateContainsOrderBy_NET9_0.md} | 2 +- 43 files changed, 973 insertions(+), 514 deletions(-) delete mode 100644 src/GreenDonut/src/GreenDonut.Data/Expressions/QueryChainVisitor.cs create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET11_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET9_0.md delete mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET10_0.md delete mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET11_0.md delete mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET8_0.md delete mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET9_0.md delete mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET10_0.md delete mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET11_0.md delete mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET8_0.md delete mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET9_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET11_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET9_0.md rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET10_0.md => PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET10_0.md} (87%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET10_0.md => PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET11_0.md} (87%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET8_0.md => PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET8_0.md} (87%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET8_0.md => PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET9_0.md} (87%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET10_0.md => PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET10_0.md} (88%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET11_0.md => PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET11_0.md} (88%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET8_0.md => PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET8_0.md} (89%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET9_0.md => PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET9_0.md} (89%) create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET10_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET11_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET8_0.md create mode 100644 src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET9_0.md rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md => PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET10_0.md} (85%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md => PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET11_0.md} (85%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md => PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET8_0.md} (85%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md => PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET9_0.md} (85%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET11_0.md => PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET10_0.md} (84%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET11_0.md => PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET11_0.md} (84%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET9_0.md => PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET8_0.md} (85%) rename src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/{PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET9_0.md => PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET9_0.md} (85%) diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs index fc5a7373cb0..937c67f9221 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExpressionHelpers.cs @@ -343,16 +343,8 @@ private static bool IsNullable(LambdaExpression expression) } // For computed key expressions (method calls, concatenation, etc.) we cannot inspect - // NRT annotations at runtime, so they are treated as non-nullable and no null - // handling is emitted into the generated WHERE clause. - // - // Known limitation: a computed key that can actually yield null (for example - // t.Products.OrderBy(p => p.Price).First().Price over a possibly-empty child - // collection) is not covered. Such a row sorts to the NULL end and is then silently - // dropped from later keyset pages, because its SQL comparisons evaluate to UNKNOWN, - // and building a cursor over a First() key throws on the empty collection. The - // navigation-path nullability handling added in #9955 does not extend to computed - // keys; supporting them is deferred to a follow-up. + // NRT annotations at runtime. Treat as non-nullable, the safe default that avoids + // injecting spurious null-handling into the generated WHERE clause. return false; } @@ -773,7 +765,7 @@ public readonly struct OrderRewriterResult( public ReadOnlySpan OrderMethods => CollectionsMarshal.AsSpan(orderMethods); } - private sealed class OrderByRemovalRewriter : QueryChainVisitor + private sealed class OrderByRemovalRewriter : ExpressionVisitor { private readonly List _orderExpressions = []; private readonly List _orderMethods = []; @@ -805,6 +797,8 @@ protected override Expression VisitMethodCall(MethodCallExpression node) return base.VisitMethodCall(node); } + protected override Expression VisitLambda(Expression node) => node; + private static Expression StripQuotes(Expression e) { while (e.NodeType == ExpressionType.Quote) diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs index e620e36c1ae..18914a339cf 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ExtractOrderPropertiesVisitor.cs @@ -2,45 +2,44 @@ namespace GreenDonut.Data.Expressions; -internal sealed class ExtractOrderPropertiesVisitor : QueryChainVisitor +internal sealed class ExtractOrderPropertiesVisitor : ExpressionVisitor { private const string OrderByMethod = "OrderBy"; private const string ThenByMethod = "ThenBy"; private const string OrderByDescendingMethod = "OrderByDescending"; private const string ThenByDescendingMethod = "ThenByDescending"; - private ParameterExpression? _orderKeyParameter; - public List OrderProperties { get; } = []; protected override Expression VisitMethodCall(MethodCallExpression node) { - if (_orderKeyParameter is null - && (node.Method.Name == OrderByMethod - || node.Method.Name == ThenByMethod - || node.Method.Name == OrderByDescendingMethod - || node.Method.Name == ThenByDescendingMethod)) + if (node.Method.Name == OrderByMethod + || node.Method.Name == ThenByMethod + || node.Method.Name == OrderByDescendingMethod + || node.Method.Name == ThenByDescendingMethod) { var lambda = StripQuotes(node.Arguments[1]); - - _orderKeyParameter = lambda.Parameters[0]; - Visit(lambda.Body); - _orderKeyParameter = null; + new OrderPropertyVisitor(lambda.Parameters[0], OrderProperties).Visit(lambda.Body); } return base.VisitMethodCall(node); } - protected override Expression VisitMember(MemberExpression node) + protected override Expression VisitLambda(Expression node) => node; + + private sealed class OrderPropertyVisitor( + ParameterExpression orderKeyParameter, + List orderProperties) + : ExpressionVisitor { - // an order key is a lambda. we only collect members rooted at that lambda's own - // parameter; members rooted on nested lambdas or intermediate results cannot be - // hoisted into the selector. - if (_orderKeyParameter is not null && node.Expression == _orderKeyParameter) + protected override Expression VisitMember(MemberExpression node) { - OrderProperties.Add(node); - } + if (node.Expression == orderKeyParameter) + { + orderProperties.Add(node); + } - return base.VisitMember(node); + return base.VisitMember(node); + } } private static LambdaExpression StripQuotes(Expression expression) diff --git a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs index 869e21839fe..e98ee316920 100644 --- a/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs +++ b/src/GreenDonut/src/GreenDonut.Data.EntityFramework/Expressions/ReverseOrderExpressionRewriter.cs @@ -3,7 +3,7 @@ namespace GreenDonut.Data.Expressions; -public class ReverseOrderExpressionRewriter : QueryChainVisitor +public class ReverseOrderExpressionRewriter : ExpressionVisitor { private static readonly MethodInfo s_orderByMethod = typeof(Queryable).GetMethods() .First(m => m.Name == nameof(Queryable.OrderBy) && m.GetParameters().Length == 2); @@ -52,6 +52,8 @@ protected override Expression VisitMethodCall(MethodCallExpression node) return base.VisitMethodCall(node); } + protected override Expression VisitLambda(Expression node) => node; + public static IQueryable Rewrite(IQueryable query) { var reversedExpression = new ReverseOrderExpressionRewriter().Visit(query.Expression); diff --git a/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs b/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs index bdd558a6c11..16ec6c2c68d 100644 --- a/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs +++ b/src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKeyParser.cs @@ -1,13 +1,12 @@ using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; -using GreenDonut.Data.Expressions; namespace GreenDonut.Data.Cursors; /// /// This expression visitor will collect the cursor keys from a query expression. /// -public sealed class CursorKeyParser : QueryChainVisitor +public sealed class CursorKeyParser : ExpressionVisitor { private readonly List _keys = []; @@ -16,6 +15,8 @@ public sealed class CursorKeyParser : QueryChainVisitor protected override Expression VisitExtension(Expression node) => node.CanReduce ? base.VisitExtension(node) : node; + protected override Expression VisitLambda(Expression node) => node; + protected override Expression VisitMethodCall(MethodCallExpression node) { if (IsOrderBy(node)) diff --git a/src/GreenDonut/src/GreenDonut.Data/Expressions/QueryChainVisitor.cs b/src/GreenDonut/src/GreenDonut.Data/Expressions/QueryChainVisitor.cs deleted file mode 100644 index 6fe51c66da9..00000000000 --- a/src/GreenDonut/src/GreenDonut.Data/Expressions/QueryChainVisitor.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Linq.Expressions; - -namespace GreenDonut.Data.Expressions; - -/// -/// A base class for expression visitors that inspect or rewrite the top-level -/// method chain of a query. Order operations that are relevant for pagination -/// only appear on this chain. Lambda arguments (predicates, projections, key -/// selectors) belong to their operator and are not traversed automatically; -/// a visitor that needs an order key lambda inspects it explicitly. -/// -public abstract class QueryChainVisitor : ExpressionVisitor -{ - /// - /// Returns the lambda unchanged so that lambda bodies are excluded from the - /// traversal. - /// - protected sealed override Expression VisitLambda(Expression node) => node; -} diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperIntegrationTests.cs b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperIntegrationTests.cs index 776f98c236b..4d05fc95922 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperIntegrationTests.cs +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperIntegrationTests.cs @@ -276,6 +276,51 @@ public async Task BatchPaging_First_5() snapshot.MatchMarkdownSnapshot(); } + [Fact] + public async Task ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy() + { + // Arrange + var snapshot = Snapshot.Create(postFix: TestEnvironment.TargetFramework); + + var connectionString = CreateConnectionString(); + await SeedAsync(connectionString); + using var capture = new CapturePagingQueryInterceptor(); + + // Act + await using var context = new CatalogContext(connectionString); + + var results = await context.Products + .Where(t => + (t.BrandId == 1 || t.BrandId == 2 || t.BrandId == 3) + && t.Brand!.Products + .AsQueryable() + .OrderByDescending(p => p.Name) + .First() + .Id > 0) + .OrderBy(p => p.Name) + .ThenBy(p => p.Id) + .ToBatchPageAsync( + k => k.BrandId, + new PagingArguments { First = 2 }, + Xunit.TestContext.Current.CancellationToken); + + // Assert + foreach (var page in results) + { + snapshot.Add( + new + { + First = page.Value.CreateStartCursor(), + Last = page.Value.CreateEndCursor(), + Items = page.Value.Items.Select(t => new { t.Id, t.Name }) + }, + name: page.Key.ToString()); + } + + snapshot.AddQueries(capture.Queries); + snapshot.MatchMarkdownSnapshot(); + } + [Fact] public async Task BatchPaging_Last_5() { diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs index 71dedcc6325..89817972bf0 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/PagingHelperTests.cs @@ -335,7 +335,7 @@ await context.Brands } [Fact] - public async Task QueryContext_Selector_With_Nested_OrderBy_Forward_Paging() + public async Task ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy() { // Arrange using var interceptor = new CapturePagingQueryInterceptor(); @@ -378,7 +378,7 @@ public async Task QueryContext_Selector_With_Nested_OrderBy_Forward_Paging() } [Fact] - public async Task QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties() + public async Task ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy() { // Arrange using var interceptor = new CapturePagingQueryInterceptor(); @@ -421,7 +421,7 @@ public async Task QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner } [Fact] - public async Task QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging() + public async Task ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy() { // Arrange using var interceptor = new CapturePagingQueryInterceptor(); @@ -457,7 +457,7 @@ public async Task QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging() } [Fact] - public async Task QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging() + public async Task ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy() { // Arrange using var interceptor = new CapturePagingQueryInterceptor(); @@ -493,7 +493,7 @@ public async Task QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging() } [Fact] - public async Task QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging() + public async Task ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy() { // Arrange using var interceptor = new CapturePagingQueryInterceptor(); @@ -505,9 +505,13 @@ public async Task QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging() // (Brand.Products) must be hoisted into the selector so cursors can be // created, while the inner key (Product.Price) must not be. var query = new QueryContext( - Selector: t => new Brand { Id = t.Id, Name = t.Name }, + Selector: t => new Brand { Id = t.Id }, Sorting: new SortDefinition() - .AddAscending(t => t.Products.OrderBy(p => p.Price).First().Price) + .AddAscending(t => t.Products + .Where(p => t.Name.Length > 0) + .OrderBy(p => p.Price) + .First() + .Price) .AddAscending(t => t.Id)); var arguments = new PagingArguments(first: 2); @@ -530,7 +534,7 @@ public async Task QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging() } [Fact] - public async Task QueryContext_OrderKey_With_Nested_OrderBy_Second_Page() + public async Task ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy() { // Arrange using var interceptor = new CapturePagingQueryInterceptor(); @@ -538,9 +542,13 @@ public async Task QueryContext_OrderKey_With_Nested_OrderBy_Second_Page() await SeedAsync(connectionString); var query = new QueryContext( - Selector: t => new Brand { Id = t.Id, Name = t.Name }, + Selector: t => new Brand { Id = t.Id }, Sorting: new SortDefinition() - .AddAscending(t => t.Products.OrderBy(p => p.Price).First().Price) + .AddAscending(t => t.Products + .Where(p => t.Name.Length > 0) + .OrderBy(p => p.Price) + .First() + .Price) .AddAscending(t => t.Id)); await using var context = new CatalogContext(connectionString); @@ -556,10 +564,11 @@ public async Task QueryContext_OrderKey_With_Nested_OrderBy_Second_Page() page = await context.Brands.With(query).ToPageAsync(arguments, Xunit.TestContext.Current.CancellationToken); // Assert - Snapshot + var snapshot = Snapshot .Create(postFix: TestEnvironment.TargetFramework) - .AddQueries(interceptor.Queries) - .MatchMarkdown(); + .AddQueries(interceptor.Queries); + snapshot.Add(page.Select(t => t.Id).ToArray(), "Page"); + snapshot.MatchMarkdown(); } [Fact] diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET10_0.md new file mode 100644 index 00000000000..8f31392bcff --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET10_0.md @@ -0,0 +1,98 @@ +# ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy + +## 1 + +```json +{ + "First": "e31Qcm9kdWN0IDAtMDox", + "Last": "e31Qcm9kdWN0IDAtMToy", + "Items": [ + { + "Id": 1, + "Name": "Product 0-0" + }, + { + "Id": 2, + "Name": "Product 0-1" + } + ] +} +``` + +## 2 + +```json +{ + "First": "e31Qcm9kdWN0IDEtMDoxMDE=", + "Last": "e31Qcm9kdWN0IDEtMToxMDI=", + "Items": [ + { + "Id": 101, + "Name": "Product 1-0" + }, + { + "Id": 102, + "Name": "Product 1-1" + } + ] +} +``` + +## 3 + +```json +{ + "First": "e31Qcm9kdWN0IDItMDoyMDE=", + "Last": "e31Qcm9kdWN0IDItMToyMDI=", + "Items": [ + { + "Id": 201, + "Name": "Product 2-0" + }, + { + "Id": 202, + "Name": "Product 2-1" + } + ] +} +``` + +## SQL 0 + +```sql +SELECT s."BrandId", s1."Id", s1."AvailableStock", s1."BrandId", s1."Description", s1."ImageFileName", s1."MaxStockThreshold", s1."Name", s1."OnReorder", s1."Price", s1."RestockThreshold", s1."TypeId", s1."Id0" +FROM ( + SELECT p."BrandId" + FROM "Products" AS p + INNER JOIN "Brands" AS b ON p."BrandId" = b."Id" + WHERE p."BrandId" IN (1, 2, 3) AND ( + SELECT p0."Id" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" + ORDER BY p0."Name" DESC + LIMIT 1) > 0 + GROUP BY p."BrandId" +) AS s +LEFT JOIN ( + SELECT s0."Id", s0."AvailableStock", s0."BrandId", s0."Description", s0."ImageFileName", s0."MaxStockThreshold", s0."Name", s0."OnReorder", s0."Price", s0."RestockThreshold", s0."TypeId", s0."Id0" + FROM ( + SELECT p1."Id", p1."AvailableStock", p1."BrandId", p1."Description", p1."ImageFileName", p1."MaxStockThreshold", p1."Name", p1."OnReorder", p1."Price", p1."RestockThreshold", p1."TypeId", b0."Id" AS "Id0", ROW_NUMBER() OVER(PARTITION BY p1."BrandId" ORDER BY p1."Name", p1."Id") AS row + FROM "Products" AS p1 + INNER JOIN "Brands" AS b0 ON p1."BrandId" = b0."Id" + WHERE (p1."BrandId" = 1 OR p1."BrandId" = 2 OR p1."BrandId" = 3) AND ( + SELECT p2."Id" + FROM "Products" AS p2 + WHERE b0."Id" = p2."BrandId" + ORDER BY p2."Name" DESC + LIMIT 1) > 0 + ) AS s0 + WHERE s0.row <= 3 +) AS s1 ON s."BrandId" = s1."BrandId" +ORDER BY s."BrandId", s1."BrandId", s1."Name", s1."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => ((((t.BrandId == 1) OrElse (t.BrandId == 2)) OrElse (t.BrandId == 3)) AndAlso (t.Brand.Products.AsQueryable().OrderByDescending(p => p.Name).First().Id > 0))).GroupBy(k => k.BrandId).Select(g => new Group`2() {Key = g.Key, Items = g.OrderBy(p => p.Name).ThenBy(p => p.Id).Take(3).ToList()}) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET11_0.md new file mode 100644 index 00000000000..f2655d573db --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET11_0.md @@ -0,0 +1,98 @@ +# ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy + +## 1 + +```json +{ + "First": "e31Qcm9kdWN0IDAtMDox", + "Last": "e31Qcm9kdWN0IDAtMToy", + "Items": [ + { + "Id": 1, + "Name": "Product 0-0" + }, + { + "Id": 2, + "Name": "Product 0-1" + } + ] +} +``` + +## 2 + +```json +{ + "First": "e31Qcm9kdWN0IDEtMDoxMDE=", + "Last": "e31Qcm9kdWN0IDEtMToxMDI=", + "Items": [ + { + "Id": 101, + "Name": "Product 1-0" + }, + { + "Id": 102, + "Name": "Product 1-1" + } + ] +} +``` + +## 3 + +```json +{ + "First": "e31Qcm9kdWN0IDItMDoyMDE=", + "Last": "e31Qcm9kdWN0IDItMToyMDI=", + "Items": [ + { + "Id": 201, + "Name": "Product 2-0" + }, + { + "Id": 202, + "Name": "Product 2-1" + } + ] +} +``` + +## SQL 0 + +```sql +SELECT s."BrandId", s1."Id", s1."AvailableStock", s1."BrandId", s1."Description", s1."ImageFileName", s1."MaxStockThreshold", s1."Name", s1."OnReorder", s1."Price", s1."RestockThreshold", s1."TypeId" +FROM ( + SELECT p."BrandId" + FROM "Products" AS p + INNER JOIN "Brands" AS b ON p."BrandId" = b."Id" + WHERE p."BrandId" IN (1, 2, 3) AND ( + SELECT p0."Id" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" + ORDER BY p0."Name" DESC + LIMIT 1) > 0 + GROUP BY p."BrandId" +) AS s +LEFT JOIN ( + SELECT s0."Id", s0."AvailableStock", s0."BrandId", s0."Description", s0."ImageFileName", s0."MaxStockThreshold", s0."Name", s0."OnReorder", s0."Price", s0."RestockThreshold", s0."TypeId" + FROM ( + SELECT p1."Id", p1."AvailableStock", p1."BrandId", p1."Description", p1."ImageFileName", p1."MaxStockThreshold", p1."Name", p1."OnReorder", p1."Price", p1."RestockThreshold", p1."TypeId", ROW_NUMBER() OVER(PARTITION BY p1."BrandId" ORDER BY p1."Name", p1."Id") AS row + FROM "Products" AS p1 + INNER JOIN "Brands" AS b0 ON p1."BrandId" = b0."Id" + WHERE (p1."BrandId" = 1 OR p1."BrandId" = 2 OR p1."BrandId" = 3) AND ( + SELECT p2."Id" + FROM "Products" AS p2 + WHERE b0."Id" = p2."BrandId" + ORDER BY p2."Name" DESC + LIMIT 1) > 0 + ) AS s0 + WHERE s0.row <= 3 +) AS s1 ON s."BrandId" = s1."BrandId" +ORDER BY s."BrandId", s1."BrandId", s1."Name", s1."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => ((((t.BrandId == 1) OrElse (t.BrandId == 2)) OrElse (t.BrandId == 3)) AndAlso (t.Brand.Products.AsQueryable().OrderByDescending(p => p.Name).First().Id > 0))).GroupBy(k => k.BrandId).Select(g => new Group`2() {Key = g.Key, Items = g.OrderBy(p => p.Name).ThenBy(p => p.Id).Take(3).ToList()}) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET8_0.md new file mode 100644 index 00000000000..1c54fa93130 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET8_0.md @@ -0,0 +1,98 @@ +# ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy + +## 1 + +```json +{ + "First": "e31Qcm9kdWN0IDAtMDox", + "Last": "e31Qcm9kdWN0IDAtMToy", + "Items": [ + { + "Id": 1, + "Name": "Product 0-0" + }, + { + "Id": 2, + "Name": "Product 0-1" + } + ] +} +``` + +## 2 + +```json +{ + "First": "e31Qcm9kdWN0IDEtMDoxMDE=", + "Last": "e31Qcm9kdWN0IDEtMToxMDI=", + "Items": [ + { + "Id": 101, + "Name": "Product 1-0" + }, + { + "Id": 102, + "Name": "Product 1-1" + } + ] +} +``` + +## 3 + +```json +{ + "First": "e31Qcm9kdWN0IDItMDoyMDE=", + "Last": "e31Qcm9kdWN0IDItMToyMDI=", + "Items": [ + { + "Id": 201, + "Name": "Product 2-0" + }, + { + "Id": 202, + "Name": "Product 2-1" + } + ] +} +``` + +## SQL 0 + +```sql +SELECT t."BrandId", t0."Id", t0."AvailableStock", t0."BrandId", t0."Description", t0."ImageFileName", t0."MaxStockThreshold", t0."Name", t0."OnReorder", t0."Price", t0."RestockThreshold", t0."TypeId", t0."Id0" +FROM ( + SELECT p."BrandId" + FROM "Products" AS p + INNER JOIN "Brands" AS b ON p."BrandId" = b."Id" + WHERE p."BrandId" IN (1, 2, 3) AND ( + SELECT p0."Id" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" + ORDER BY p0."Name" DESC + LIMIT 1) > 0 + GROUP BY p."BrandId" +) AS t +LEFT JOIN ( + SELECT t1."Id", t1."AvailableStock", t1."BrandId", t1."Description", t1."ImageFileName", t1."MaxStockThreshold", t1."Name", t1."OnReorder", t1."Price", t1."RestockThreshold", t1."TypeId", t1."Id0" + FROM ( + SELECT p1."Id", p1."AvailableStock", p1."BrandId", p1."Description", p1."ImageFileName", p1."MaxStockThreshold", p1."Name", p1."OnReorder", p1."Price", p1."RestockThreshold", p1."TypeId", b0."Id" AS "Id0", ROW_NUMBER() OVER(PARTITION BY p1."BrandId" ORDER BY p1."Name", p1."Id") AS row + FROM "Products" AS p1 + INNER JOIN "Brands" AS b0 ON p1."BrandId" = b0."Id" + WHERE (p1."BrandId" = 1 OR p1."BrandId" = 2 OR p1."BrandId" = 3) AND ( + SELECT p2."Id" + FROM "Products" AS p2 + WHERE b0."Id" = p2."BrandId" + ORDER BY p2."Name" DESC + LIMIT 1) > 0 + ) AS t1 + WHERE t1.row <= 3 +) AS t0 ON t."BrandId" = t0."BrandId" +ORDER BY t."BrandId", t0."BrandId", t0."Name", t0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => ((((t.BrandId == 1) OrElse (t.BrandId == 2)) OrElse (t.BrandId == 3)) AndAlso (t.Brand.Products.AsQueryable().OrderByDescending(p => p.Name).First().Id > 0))).GroupBy(k => k.BrandId).Select(g => new Group`2() {Key = g.Key, Items = g.OrderBy(p => p.Name).ThenBy(p => p.Id).Take(3).ToList()}) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET9_0.md new file mode 100644 index 00000000000..8f31392bcff --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperIntegrationTests.ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy_NET9_0.md @@ -0,0 +1,98 @@ +# ToBatchPageAsync_Should_PreserveNestedOrdering_When_PredicateContainsOrderBy + +## 1 + +```json +{ + "First": "e31Qcm9kdWN0IDAtMDox", + "Last": "e31Qcm9kdWN0IDAtMToy", + "Items": [ + { + "Id": 1, + "Name": "Product 0-0" + }, + { + "Id": 2, + "Name": "Product 0-1" + } + ] +} +``` + +## 2 + +```json +{ + "First": "e31Qcm9kdWN0IDEtMDoxMDE=", + "Last": "e31Qcm9kdWN0IDEtMToxMDI=", + "Items": [ + { + "Id": 101, + "Name": "Product 1-0" + }, + { + "Id": 102, + "Name": "Product 1-1" + } + ] +} +``` + +## 3 + +```json +{ + "First": "e31Qcm9kdWN0IDItMDoyMDE=", + "Last": "e31Qcm9kdWN0IDItMToyMDI=", + "Items": [ + { + "Id": 201, + "Name": "Product 2-0" + }, + { + "Id": 202, + "Name": "Product 2-1" + } + ] +} +``` + +## SQL 0 + +```sql +SELECT s."BrandId", s1."Id", s1."AvailableStock", s1."BrandId", s1."Description", s1."ImageFileName", s1."MaxStockThreshold", s1."Name", s1."OnReorder", s1."Price", s1."RestockThreshold", s1."TypeId", s1."Id0" +FROM ( + SELECT p."BrandId" + FROM "Products" AS p + INNER JOIN "Brands" AS b ON p."BrandId" = b."Id" + WHERE p."BrandId" IN (1, 2, 3) AND ( + SELECT p0."Id" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" + ORDER BY p0."Name" DESC + LIMIT 1) > 0 + GROUP BY p."BrandId" +) AS s +LEFT JOIN ( + SELECT s0."Id", s0."AvailableStock", s0."BrandId", s0."Description", s0."ImageFileName", s0."MaxStockThreshold", s0."Name", s0."OnReorder", s0."Price", s0."RestockThreshold", s0."TypeId", s0."Id0" + FROM ( + SELECT p1."Id", p1."AvailableStock", p1."BrandId", p1."Description", p1."ImageFileName", p1."MaxStockThreshold", p1."Name", p1."OnReorder", p1."Price", p1."RestockThreshold", p1."TypeId", b0."Id" AS "Id0", ROW_NUMBER() OVER(PARTITION BY p1."BrandId" ORDER BY p1."Name", p1."Id") AS row + FROM "Products" AS p1 + INNER JOIN "Brands" AS b0 ON p1."BrandId" = b0."Id" + WHERE (p1."BrandId" = 1 OR p1."BrandId" = 2 OR p1."BrandId" = 3) AND ( + SELECT p2."Id" + FROM "Products" AS p2 + WHERE b0."Id" = p2."BrandId" + ORDER BY p2."Name" DESC + LIMIT 1) > 0 + ) AS s0 + WHERE s0.row <= 3 +) AS s1 ON s."BrandId" = s1."BrandId" +ORDER BY s."BrandId", s1."BrandId", s1."Name", s1."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(t => ((((t.BrandId == 1) OrElse (t.BrandId == 2)) OrElse (t.BrandId == 3)) AndAlso (t.Brand.Products.AsQueryable().OrderByDescending(p => p.Name).First().Id > 0))).GroupBy(k => k.BrandId).Select(g => new Group`2() {Key = g.Key, Items = g.OrderBy(p => p.Name).ThenBy(p => p.Id).Take(3).ToList()}) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET10_0.md deleted file mode 100644 index d25a8af60d0..00000000000 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET10_0.md +++ /dev/null @@ -1,32 +0,0 @@ -# QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging - -## SQL 0 - -```sql --- @p='3' -SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @p -) AS b0 -LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 0 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) -``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET11_0.md deleted file mode 100644 index d25a8af60d0..00000000000 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET11_0.md +++ /dev/null @@ -1,32 +0,0 @@ -# QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging - -## SQL 0 - -```sql --- @p='3' -SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @p -) AS b0 -LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 0 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) -``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET8_0.md deleted file mode 100644 index ae8cb27dbf1..00000000000 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET8_0.md +++ /dev/null @@ -1,32 +0,0 @@ -# QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging - -## SQL 0 - -```sql --- @__p_0='3' -SELECT t."Id", t."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @__p_0 -) AS t -LEFT JOIN "Products" AS p0 ON t."Id" = p0."BrandId" -ORDER BY t.c, t."Id" -``` - -## Expression 0 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) -``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET9_0.md deleted file mode 100644 index 624616b8d1d..00000000000 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging_NET9_0.md +++ /dev/null @@ -1,32 +0,0 @@ -# QueryContext_OrderKey_With_Nested_OrderBy_Forward_Paging - -## SQL 0 - -```sql --- @__p_0='3' -SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @__p_0 -) AS b0 -LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 0 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) -``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET10_0.md deleted file mode 100644 index 02bb7f257c3..00000000000 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET10_0.md +++ /dev/null @@ -1,76 +0,0 @@ -# QueryContext_OrderKey_With_Nested_OrderBy_Second_Page - -## SQL 0 - -```sql --- @p='3' -SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @p -) AS b0 -LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 0 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) -``` - -## SQL 1 - -```sql --- @value='0' --- @value1='2' --- @p='3' -SELECT b0."Id", b0."Name", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - WHERE ( - SELECT p0."Price" - FROM "Products" AS p0 - WHERE b."Id" = p0."BrandId" - ORDER BY p0."Price" - LIMIT 1) > @value OR (( - SELECT p1."Price" - FROM "Products" AS p1 - WHERE b."Id" = p1."BrandId" - ORDER BY p1."Price" - LIMIT 1) = @value AND b."Id" > @value1) - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @p -) AS b0 -LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 1 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}) -``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET11_0.md deleted file mode 100644 index f0114ca1043..00000000000 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET11_0.md +++ /dev/null @@ -1,76 +0,0 @@ -# QueryContext_OrderKey_With_Nested_OrderBy_Second_Page - -## SQL 0 - -```sql --- @p='3' -SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @p -) AS b0 -LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 0 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) -``` - -## SQL 1 - -```sql --- @value='0' --- @value2='2' --- @p='3' -SELECT b0."Id", b0."Name", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - WHERE ( - SELECT p0."Price" - FROM "Products" AS p0 - WHERE b."Id" = p0."BrandId" - ORDER BY p0."Price" - LIMIT 1) > @value OR (( - SELECT p1."Price" - FROM "Products" AS p1 - WHERE b."Id" = p1."BrandId" - ORDER BY p1."Price" - LIMIT 1) = @value AND b."Id" > @value2) - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @p -) AS b0 -LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 1 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}) -``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET8_0.md deleted file mode 100644 index be06e5ec9b5..00000000000 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET8_0.md +++ /dev/null @@ -1,76 +0,0 @@ -# QueryContext_OrderKey_With_Nested_OrderBy_Second_Page - -## SQL 0 - -```sql --- @__p_0='3' -SELECT t."Id", t."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @__p_0 -) AS t -LEFT JOIN "Products" AS p0 ON t."Id" = p0."BrandId" -ORDER BY t.c, t."Id" -``` - -## Expression 0 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) -``` - -## SQL 1 - -```sql --- @__value_0='0' --- @__value_1='2' --- @__p_2='3' -SELECT t."Id", t."Name", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - WHERE ( - SELECT p0."Price" - FROM "Products" AS p0 - WHERE b."Id" = p0."BrandId" - ORDER BY p0."Price" - LIMIT 1) > @__value_0 OR (( - SELECT p1."Price" - FROM "Products" AS p1 - WHERE b."Id" = p1."BrandId" - ORDER BY p1."Price" - LIMIT 1) = @__value_0 AND b."Id" > @__value_1) - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @__p_2 -) AS t -LEFT JOIN "Products" AS p2 ON t."Id" = p2."BrandId" -ORDER BY t.c, t."Id" -``` - -## Expression 1 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}) -``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET9_0.md deleted file mode 100644 index 60694b56eac..00000000000 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_OrderKey_With_Nested_OrderBy_Second_Page_NET9_0.md +++ /dev/null @@ -1,76 +0,0 @@ -# QueryContext_OrderKey_With_Nested_OrderBy_Second_Page - -## SQL 0 - -```sql --- @__p_0='3' -SELECT b0."Id", b0."Name", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @__p_0 -) AS b0 -LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 0 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}).Take(3) -``` - -## SQL 1 - -```sql --- @__value_0='0' --- @__value_1='2' --- @__p_2='3' -SELECT b0."Id", b0."Name", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId" -FROM ( - SELECT b."Id", b."Name", ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1) AS c - FROM "Brands" AS b - WHERE ( - SELECT p0."Price" - FROM "Products" AS p0 - WHERE b."Id" = p0."BrandId" - ORDER BY p0."Price" - LIMIT 1) > @__value_0 OR (( - SELECT p1."Price" - FROM "Products" AS p1 - WHERE b."Id" = p1."BrandId" - ORDER BY p1."Price" - LIMIT 1) = @__value_0 AND b."Id" > @__value_1) - ORDER BY ( - SELECT p."Price" - FROM "Products" AS p - WHERE b."Id" = p."BrandId" - ORDER BY p."Price" - LIMIT 1), b."Id" - LIMIT @__p_2 -) AS b0 -LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" -ORDER BY b0.c, b0."Id" -``` - -## Expression 1 - -```text -[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Name = t.Name, Products = t.Products}) -``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET10_0.md new file mode 100644 index 00000000000..931f072927d --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET10_0.md @@ -0,0 +1,32 @@ +# ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy + +## SQL 0 + +```sql +-- @p='3' +SELECT b0."Id", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET11_0.md new file mode 100644 index 00000000000..931f072927d --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET11_0.md @@ -0,0 +1,32 @@ +# ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy + +## SQL 0 + +```sql +-- @p='3' +SELECT b0."Id", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET8_0.md new file mode 100644 index 00000000000..fed71b0a342 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET8_0.md @@ -0,0 +1,32 @@ +# ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT t."Id", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId", t."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_0 +) AS t +LEFT JOIN "Products" AS p0 ON t."Id" = p0."BrandId" +ORDER BY t.c, t."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET9_0.md new file mode 100644 index 00000000000..b2bb1da731a --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy_NET9_0.md @@ -0,0 +1,32 @@ +# ToPageAsync_Should_CreateCursor_When_OrderKeyContainsNestedOrderBy + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b0."Id", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_0 +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}).Take(3) +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET10_0.md similarity index 87% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET10_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET10_0.md index 7b941f49038..655bd55d7fe 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET10_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET10_0.md @@ -1,4 +1,4 @@ -# QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging +# ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET11_0.md similarity index 87% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET10_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET11_0.md index 92c7d901acb..655bd55d7fe 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET10_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET11_0.md @@ -1,4 +1,4 @@ -# QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging +# ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET8_0.md similarity index 87% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET8_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET8_0.md index a166ad01f46..0205baa8465 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET8_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET8_0.md @@ -1,4 +1,4 @@ -# QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging +# ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET9_0.md similarity index 87% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET8_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET9_0.md index 68a57bb7683..0205baa8465 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET8_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy_NET9_0.md @@ -1,4 +1,4 @@ -# QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging +# ToPageAsync_Should_CreateCursor_When_PredicateContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET10_0.md similarity index 88% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET10_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET10_0.md index a1bf9c2e363..66a1cd67eb1 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET10_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET10_0.md @@ -1,4 +1,4 @@ -# QueryContext_Selector_With_Nested_OrderBy_Forward_Paging +# ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET11_0.md similarity index 88% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET11_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET11_0.md index a1bf9c2e363..66a1cd67eb1 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET11_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET11_0.md @@ -1,4 +1,4 @@ -# QueryContext_Selector_With_Nested_OrderBy_Forward_Paging +# ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET8_0.md similarity index 89% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET8_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET8_0.md index 08a8d64a9a5..a0d28aa4aff 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET8_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET8_0.md @@ -1,4 +1,4 @@ -# QueryContext_Selector_With_Nested_OrderBy_Forward_Paging +# ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET9_0.md similarity index 89% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET9_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET9_0.md index 08a8d64a9a5..a0d28aa4aff 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Forward_Paging_NET9_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy_NET9_0.md @@ -1,4 +1,4 @@ -# QueryContext_Selector_With_Nested_OrderBy_Forward_Paging +# ToPageAsync_Should_CreateCursor_When_SelectorContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET10_0.md new file mode 100644 index 00000000000..89d2156aee9 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET10_0.md @@ -0,0 +1,85 @@ +# ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy + +## SQL 0 + +```sql +-- @p='3' +SELECT b0."Id", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}).Take(3) +``` + +## SQL 1 + +```sql +-- @value='0' +-- @value1='2' +-- @p='3' +SELECT b0."Id", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + WHERE ( + SELECT p0."Price" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" AND length(b."Name")::int > 0 + ORDER BY p0."Price" + LIMIT 1) > @value OR (( + SELECT p1."Price" + FROM "Products" AS p1 + WHERE b."Id" = p1."BrandId" AND length(b."Name")::int > 0 + ORDER BY p1."Price" + LIMIT 1) = @value AND b."Id" > @value1) + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 1 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}) +``` + +## Page + +```json +[ + 3, + 4 +] +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET11_0.md new file mode 100644 index 00000000000..1c144dadb61 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET11_0.md @@ -0,0 +1,85 @@ +# ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy + +## SQL 0 + +```sql +-- @p='3' +SELECT b0."Id", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}).Take(3) +``` + +## SQL 1 + +```sql +-- @value='0' +-- @value2='2' +-- @p='3' +SELECT b0."Id", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + WHERE ( + SELECT p0."Price" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" AND length(b."Name")::int > 0 + ORDER BY p0."Price" + LIMIT 1) > @value OR (( + SELECT p1."Price" + FROM "Products" AS p1 + WHERE b."Id" = p1."BrandId" AND length(b."Name")::int > 0 + ORDER BY p1."Price" + LIMIT 1) = @value AND b."Id" > @value2) + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @p +) AS b0 +LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 1 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}) +``` + +## Page + +```json +[ + 3, + 4 +] +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET8_0.md new file mode 100644 index 00000000000..0f059beadc8 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET8_0.md @@ -0,0 +1,85 @@ +# ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT t."Id", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId", t."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_0 +) AS t +LEFT JOIN "Products" AS p0 ON t."Id" = p0."BrandId" +ORDER BY t.c, t."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}).Take(3) +``` + +## SQL 1 + +```sql +-- @__value_0='0' +-- @__value_1='2' +-- @__p_2='3' +SELECT t."Id", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId", t."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + WHERE ( + SELECT p0."Price" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" AND length(b."Name")::int > 0 + ORDER BY p0."Price" + LIMIT 1) > @__value_0 OR (( + SELECT p1."Price" + FROM "Products" AS p1 + WHERE b."Id" = p1."BrandId" AND length(b."Name")::int > 0 + ORDER BY p1."Price" + LIMIT 1) = @__value_0 AND b."Id" > @__value_1) + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_2 +) AS t +LEFT JOIN "Products" AS p2 ON t."Id" = p2."BrandId" +ORDER BY t.c, t."Id" +``` + +## Expression 1 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}) +``` + +## Page + +```json +[ + 3, + 4 +] +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET9_0.md new file mode 100644 index 00000000000..ac5ababdeb0 --- /dev/null +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy_NET9_0.md @@ -0,0 +1,85 @@ +# ToPageAsync_Should_FetchSecondPage_When_OrderKeyContainsNestedOrderBy + +## SQL 0 + +```sql +-- @__p_0='3' +SELECT b0."Id", p0."Id", p0."AvailableStock", p0."BrandId", p0."Description", p0."ImageFileName", p0."MaxStockThreshold", p0."Name", p0."OnReorder", p0."Price", p0."RestockThreshold", p0."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_0 +) AS b0 +LEFT JOIN "Products" AS p0 ON b0."Id" = p0."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 0 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}).Take(3) +``` + +## SQL 1 + +```sql +-- @__value_0='0' +-- @__value_1='2' +-- @__p_2='3' +SELECT b0."Id", p2."Id", p2."AvailableStock", p2."BrandId", p2."Description", p2."ImageFileName", p2."MaxStockThreshold", p2."Name", p2."OnReorder", p2."Price", p2."RestockThreshold", p2."TypeId", b0."Name" +FROM ( + SELECT b."Id", b."Name", ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1) AS c + FROM "Brands" AS b + WHERE ( + SELECT p0."Price" + FROM "Products" AS p0 + WHERE b."Id" = p0."BrandId" AND length(b."Name")::int > 0 + ORDER BY p0."Price" + LIMIT 1) > @__value_0 OR (( + SELECT p1."Price" + FROM "Products" AS p1 + WHERE b."Id" = p1."BrandId" AND length(b."Name")::int > 0 + ORDER BY p1."Price" + LIMIT 1) = @__value_0 AND b."Id" > @__value_1) + ORDER BY ( + SELECT p."Price" + FROM "Products" AS p + WHERE b."Id" = p."BrandId" AND length(b."Name")::int > 0 + ORDER BY p."Price" + LIMIT 1), b."Id" + LIMIT @__p_2 +) AS b0 +LEFT JOIN "Products" AS p2 ON b0."Id" = p2."BrandId" +ORDER BY b0.c, b0."Id" +``` + +## Expression 1 + +```text +[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].OrderBy(t => t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price).ThenBy(t => t.Id).Where(t => ((t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) > 0) OrElse ((t.Products.Where(p => (t.Name.Length > 0)).OrderBy(p => p.Price).First().Price.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Decimal]).value) == 0) AndAlso (t.Id.CompareTo(value(GreenDonut.Data.Expressions.ExpressionHelpers+<>c__DisplayClass16_0`1[System.Int32]).value) > 0)))).Take(3).Select(t => new Brand() {Id = t.Id, Products = t.Products, Name = t.Name}) +``` + +## Page + +```json +[ + 3, + 4 +] +``` diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET10_0.md similarity index 85% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET10_0.md index d65b3ecc735..285ac93c2ab 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET10_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET10_0.md @@ -1,4 +1,4 @@ -# QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties +# ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET11_0.md similarity index 85% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET11_0.md index d65b3ecc735..285ac93c2ab 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET11_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET11_0.md @@ -1,4 +1,4 @@ -# QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties +# ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET8_0.md similarity index 85% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET8_0.md index ab78acac87f..71b9f7e53d8 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET8_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET8_0.md @@ -1,4 +1,4 @@ -# QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties +# ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET9_0.md similarity index 85% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET9_0.md index ab78acac87f..71b9f7e53d8 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties_NET9_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy_NET9_0.md @@ -1,4 +1,4 @@ -# QueryContext_Selector_With_Nested_OrderBy_Does_Not_Hoist_Inner_Order_Properties +# ToPageAsync_Should_NotHoistInnerOrderProperties_When_BackwardPagingSelectorContainsNestedOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET10_0.md similarity index 84% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET11_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET10_0.md index 92c7d901acb..7f2761126c9 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET11_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET10_0.md @@ -1,4 +1,4 @@ -# QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging +# ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET11_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET11_0.md similarity index 84% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET11_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET11_0.md index 7b941f49038..7f2761126c9 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET11_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET11_0.md @@ -1,4 +1,4 @@ -# QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging +# ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET8_0.md similarity index 85% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET9_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET8_0.md index 68a57bb7683..48edfb75855 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging_NET9_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET8_0.md @@ -1,4 +1,4 @@ -# QueryContext_Predicate_With_Nested_OrderBy_Forward_Paging +# ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy ## SQL 0 diff --git a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET9_0.md b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET9_0.md similarity index 85% rename from src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET9_0.md rename to src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET9_0.md index a166ad01f46..48edfb75855 100644 --- a/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging_NET9_0.md +++ b/src/GreenDonut/test/GreenDonut.Data.EntityFramework.Tests/__snapshots__/PagingHelperTests.ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy_NET9_0.md @@ -1,4 +1,4 @@ -# QueryContext_Predicate_With_Nested_OrderBy_Backward_Paging +# ToPageAsync_Should_PreserveNestedOrdering_When_BackwardPagingPredicateContainsOrderBy ## SQL 0