Skip to content

Commit 6ec0c34

Browse files
committed
Add test to check that ORDER BY is removed on singleton collections
1 parent 02d37a2 commit 6ec0c34

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,15 @@ public override async Task Project_single_element_from_collection_with_OrderBy_T
722722
AssertSql();
723723
}
724724

725+
public override async Task Project_single_element_from_collection_with_OrderBy_Take_OrderBy_and_FirstOrDefault(bool async)
726+
{
727+
// Cosmos client evaluation. Issue #17246.
728+
await AssertTranslationFailed(
729+
() => base.Project_single_element_from_collection_with_OrderBy_Take_OrderBy_and_FirstOrDefault(async));
730+
731+
AssertSql();
732+
}
733+
725734
public override async Task Project_single_element_from_collection_with_OrderBy_Take_and_FirstOrDefault_with_parameter(bool async)
726735
{
727736
// Cosmos client evaluation. Issue #17246.

test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,14 @@ public virtual Task Project_single_element_from_collection_with_OrderBy_Take_and
10171017
async,
10181018
ss => ss.Set<Customer>().Select(c => c.Orders.OrderBy(o => o.OrderID).Select(o => o.CustomerID).Take(1).FirstOrDefault()));
10191019

1020+
[ConditionalTheory]
1021+
[MemberData(nameof(IsAsyncData))]
1022+
public virtual Task Project_single_element_from_collection_with_OrderBy_Take_OrderBy_and_FirstOrDefault(bool async)
1023+
=> AssertQuery(
1024+
async,
1025+
ss => ss.Set<Customer>().Select(
1026+
c => c.Orders.OrderBy(o => o.OrderID).Take(1).OrderBy(o => o.OrderDate).FirstOrDefault()));
1027+
10201028
[ConditionalTheory]
10211029
[MemberData(nameof(IsAsyncData))]
10221030
public virtual Task Project_single_element_from_collection_with_OrderBy_Skip_and_FirstOrDefault(bool async)

test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,27 @@ FROM [Customers] AS [c]
768768
""");
769769
}
770770

771+
public override async Task Project_single_element_from_collection_with_OrderBy_Take_OrderBy_and_FirstOrDefault(bool async)
772+
{
773+
await base.Project_single_element_from_collection_with_OrderBy_Take_OrderBy_and_FirstOrDefault(async);
774+
775+
AssertSql(
776+
"""
777+
SELECT [o1].[OrderID], [o1].[CustomerID], [o1].[EmployeeID], [o1].[OrderDate]
778+
FROM [Customers] AS [c]
779+
OUTER APPLY (
780+
SELECT TOP(1) [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
781+
FROM (
782+
SELECT TOP(1) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
783+
FROM [Orders] AS [o]
784+
WHERE [c].[CustomerID] = [o].[CustomerID]
785+
ORDER BY [o].[OrderID]
786+
) AS [o0]
787+
ORDER BY [o0].[OrderDate]
788+
) AS [o1]
789+
""");
790+
}
791+
771792
public override async Task Project_single_element_from_collection_with_OrderBy_Skip_and_FirstOrDefault(bool async)
772793
{
773794
await base.Project_single_element_from_collection_with_OrderBy_Skip_and_FirstOrDefault(async);

0 commit comments

Comments
 (0)