diff --git a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsQueryInMemoryTest.cs index cd3f492c988..d6599b32aa5 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsQueryInMemoryTest.cs @@ -13,9 +13,4 @@ public ComplexNavigationsCollectionsQueryInMemoryTest( { //TestLoggerFactory.TestOutputHelper = testOutputHelper; } - - public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) - // Nested collection with ToList. Issue #23303. - => await Assert.ThrowsAsync( - () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest.cs index 8e91da4f8c4..0ab251441f3 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest.cs @@ -13,9 +13,4 @@ public ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest( { //TestLoggerFactory.TestOutputHelper = testOutputHelper; } - - public override Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) - // Nested collection with ToList. Issue #23303. - => Assert.ThrowsAsync( - () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); } diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsQueryTestBase.cs index 176e384ac49..0205852d3cc 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsQueryTestBase.cs @@ -414,11 +414,11 @@ public virtual Task Complex_query_with_let_collection_projection_FirstOrDefault_ async, ss => from l1 in ss.Set() orderby l1.Id - let inner = (from l2 in l1.OneToMany_Optional1 + let inner = (from l2 in ss.Set() where l2.Name != "Foo" - let innerL1s = from innerL1 in ss.Set() + let innerL1s = (from innerL1 in ss.Set() where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id) - select innerL1.Name + select innerL1.Name).AsEnumerable() select innerL1s.ToList()).FirstOrDefault() select inner.ToList(), assertOrder: true, diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs index e4f53a381d9..dd8a3675305 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs @@ -2367,31 +2367,25 @@ FROM [LevelOne] AS [l] public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) { - // Nested collection with ToList. Issue #23303. - await Assert.ThrowsAsync( - () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); + await base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async); AssertSql( - @"SELECT [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id], [t0].[c] + @"SELECT [l].[Id], [t].[Id], [t0].[Name], [t0].[Id], [t].[c] FROM [LevelOne] AS [l] -LEFT JOIN ( - SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] - FROM ( - SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] - FROM [LevelTwo] AS [l0] - WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL - ) AS [t] - WHERE [t].[row] <= 1 -) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT TOP(1) 1 AS [c], [l0].[Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +) AS [t] OUTER APPLY ( SELECT [l1].[Name], [l1].[Id] FROM [LevelOne] AS [l1] WHERE EXISTS ( SELECT 1 FROM [LevelTwo] AS [l2] - WHERE [l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Id] = [t0].[Id]) -) AS [t1] -ORDER BY [l].[Id], [t0].[Id]"); + WHERE [l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Id] = [t].[Id]) +) AS [t0] +ORDER BY [l].[Id], [t].[Id]"); } public override async Task Include_collection_with_multiple_orderbys_complex_repeated_checked(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs index 97876a43ab6..3cdbd4ef575 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs @@ -21,33 +21,34 @@ public virtual void Check_all_tests_overridden() public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) { - // Nested collection with ToList. Issue #23303. - await Assert.ThrowsAsync( - () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); + await base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async); AssertSql( - @"SELECT [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id], [t0].[c] + @"SELECT [l].[Id], [t0].[Id], [t0].[Id0], [t1].[Name], [t1].[Id], [t0].[c] FROM [Level1] AS [l] -LEFT JOIN ( - SELECT [t].[c], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Optional_Inverse2Id] - FROM ( - SELECT 1 AS [c], [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] - FROM [Level1] AS [l0] - WHERE [l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l0].[Level2_Name] <> N'Foo' OR [l0].[Level2_Name] IS NULL) - ) AS [t] - WHERE [t].[row] <= 1 -) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] OUTER APPLY ( - SELECT [l1].[Name], [l1].[Id] - FROM [Level1] AS [l1] + SELECT TOP(1) 1 AS [c], [l0].[Id], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + WHERE [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN [t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE [t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([t].[Level2_Name] <> N'Foo' OR [t].[Level2_Name] IS NULL) +) AS [t0] +OUTER APPLY ( + SELECT [l2].[Name], [l2].[Id] + FROM [Level1] AS [l2] WHERE EXISTS ( SELECT 1 - FROM [Level1] AS [l2] - WHERE [l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL AND [l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Id] = CASE - WHEN [t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + FROM [Level1] AS [l3] + WHERE [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL AND [l2].[Id] = [l3].[OneToMany_Optional_Inverse2Id] AND [l3].[Id] = CASE + WHEN [t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] END) ) AS [t1] -ORDER BY [l].[Id], [t0].[Id]"); +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0]"); } public override async Task SelectMany_with_Include1(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs index 7ecf7d3b1a2..122d22924fd 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs @@ -1245,44 +1245,34 @@ public override async Task Queryable_in_subquery_works_when_final_projection_is_ public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) { - // Nested collection with ToList. Issue #23303. - await Assert.ThrowsAsync( - () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); + await base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async); AssertSql( - @"SELECT [l].[Id], [t0].[Id], [t0].[c] + @"SELECT [l].[Id], [t].[Id], [t].[c] FROM [LevelOne] AS [l] -LEFT JOIN ( - SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] - FROM ( - SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] - FROM [LevelTwo] AS [l0] - WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL - ) AS [t] - WHERE [t].[row] <= 1 -) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t0].[Id]", - // - @"SELECT [t1].[Name], [l].[Id], [t0].[Id] +OUTER APPLY ( + SELECT TOP(1) 1 AS [c], [l0].[Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +) AS [t] +ORDER BY [l].[Id], [t].[Id]", + // + @"SELECT [t0].[Name], [l].[Id], [t].[Id] FROM [LevelOne] AS [l] -LEFT JOIN ( - SELECT [t].[Id], [t].[OneToMany_Optional_Inverse2Id] - FROM ( - SELECT [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] - FROM [LevelTwo] AS [l0] - WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL - ) AS [t] - WHERE [t].[row] <= 1 -) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT TOP(1) [l0].[Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +) AS [t] CROSS APPLY ( SELECT [l1].[Name] FROM [LevelOne] AS [l1] WHERE EXISTS ( SELECT 1 FROM [LevelTwo] AS [l2] - WHERE [l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Id] = [t0].[Id]) -) AS [t1] -ORDER BY [l].[Id], [t0].[Id]"); + WHERE [l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Id] = [t].[Id]) +) AS [t0] +ORDER BY [l].[Id], [t].[Id]"); } public override async Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest.cs index 8a557ad45d4..de8fdf38990 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest.cs @@ -14,9 +14,4 @@ public ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest( Fixture.TestSqlLoggerFactory.Clear(); //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } - - public override Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) - // Nested collection with ToList. Issue #23303. - => Assert.ThrowsAsync( - () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsQuerySqlServerTest.cs index 8758485a125..76e00e65854 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsQuerySqlServerTest.cs @@ -1091,32 +1091,25 @@ ELSE CAST(0 AS bit) public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) { - // Nested collection with ToList. Issue #23303. - - await Assert.ThrowsAsync( - () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); + await base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async); AssertSql( - @"SELECT [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id], [t0].[c] + @"SELECT [l].[Id], [t].[Id], [t0].[Name], [t0].[Id], [t].[c] FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] -LEFT JOIN ( - SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] - FROM ( - SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] - FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] - WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL - ) AS [t] - WHERE [t].[row] <= 1 -) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT TOP(1) 1 AS [c], [l0].[Id] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +) AS [t] OUTER APPLY ( SELECT [l1].[Name], [l1].[Id] FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] WHERE EXISTS ( SELECT 1 FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] - WHERE [l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Id] = [t0].[Id]) -) AS [t1] -ORDER BY [l].[Id], [t0].[Id]"); + WHERE [l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Id] = [t].[Id]) +) AS [t0] +ORDER BY [l].[Id], [t].[Id]"); } public override async Task Skip_on_grouping_element(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs index 99201186e47..fb1f557ca74 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs @@ -178,11 +178,10 @@ WHEN [t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] ORDER BY [l].[Id], [t0].[Id]"); } + [ConditionalTheory(Skip = "See issue#28058")] public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) { - // Nested collection with ToList. Issue #23303. - await Assert.ThrowsAsync( - () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); + await base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async); AssertSql( @"SELECT [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id], [t0].[c]