Skip to content

Commit

Permalink
Add regression test for #22223 (#24734)
Browse files Browse the repository at this point in the history
Resolves #22223
  • Loading branch information
smitpatel committed Apr 22, 2021
1 parent def5369 commit 0a1e3a8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -969,5 +969,23 @@ public virtual Task Take_SelectMany_correlated_subquery_take(bool async)
.Take(2)),
entryCount: 2);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Take_in_collection_projection_with_FirstOrDefault_on_top_level(bool async)
{
return AssertFirstOrDefault(
async,
ss => ss.Set<Customer>()
.Select(c => new
{
Orders = c.Orders.OrderBy(e => e.OrderDate).Take(1)
.Select(o => new
{
Title = o.CustomerID == o.Customer.City ? "A" : "B"
}).ToList()
}),
asserter: (e, a) => AssertCollection(e.Orders, a.Orders, ordered: true));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,32 @@ FROM [Customers] AS [c0]
ORDER BY [t].[CustomerID]");
}

public override async Task Take_in_collection_projection_with_FirstOrDefault_on_top_level(bool async)
{
await base.Take_in_collection_projection_with_FirstOrDefault_on_top_level(async);

AssertSql(
@"SELECT [t].[CustomerID], [t0].[Title], [t0].[OrderID], [t0].[CustomerID]
FROM (
SELECT TOP(1) [c].[CustomerID]
FROM [Customers] AS [c]
) AS [t]
OUTER APPLY (
SELECT CASE
WHEN ([t1].[CustomerID] = [c0].[City]) OR ([t1].[CustomerID] IS NULL AND [c0].[City] IS NULL) THEN N'A'
ELSE N'B'
END AS [Title], [t1].[OrderID], [c0].[CustomerID], [t1].[OrderDate]
FROM (
SELECT TOP(1) [o].[OrderID], [o].[CustomerID], [o].[OrderDate]
FROM [Orders] AS [o]
WHERE [t].[CustomerID] = [o].[CustomerID]
ORDER BY [o].[OrderDate]
) AS [t1]
LEFT JOIN [Customers] AS [c0] ON [t1].[CustomerID] = [c0].[CustomerID]
) AS [t0]
ORDER BY [t].[CustomerID], [t0].[OrderDate], [t0].[OrderID], [t0].[CustomerID]");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,11 @@ public override async Task SelectMany_with_selecting_outer_entity_column_and_inn
SqliteStrings.ApplyNotSupported,
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.SelectMany_with_selecting_outer_entity_column_and_inner_column(async))).Message);

public override async Task Take_in_collection_projection_with_FirstOrDefault_on_top_level(bool async)
=> Assert.Equal(
SqliteStrings.ApplyNotSupported,
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Take_in_collection_projection_with_FirstOrDefault_on_top_level(async))).Message);
}
}

0 comments on commit 0a1e3a8

Please sign in to comment.