diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 7da958e12cf..e0ae73449cb 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -572,7 +572,7 @@ static void UpdateLimit(SelectExpression selectExpression) innerShaperExpression); } - AddJoin(JoinType.OuterApply, ref innerSelectExpression); + AddJoin(JoinType.OuterApply, ref innerSelectExpression, out _); var offset = _clientProjections.Count; var count = innerSelectExpression._clientProjections.Count; _clientProjections.AddRange( @@ -650,7 +650,7 @@ static Expression RemoveConvert(Expression expression) #endif var parentIdentifier = GetIdentifierAccessor(this, newClientProjections, actualParentIdentifier).Item1; - outerSelectExpression.AddCrossApply(innerSelectExpression); + outerSelectExpression.AddJoin(JoinType.CrossApply, ref innerSelectExpression, out var pushdownOccurredWhenJoining); outerSelectExpression._clientProjections.AddRange(innerSelectExpression._clientProjections); outerSelectExpression._aliasForClientProjections.AddRange(innerSelectExpression._aliasForClientProjections); innerSelectExpression = outerSelectExpression; @@ -670,18 +670,29 @@ static Expression RemoveConvert(Expression expression) var innerOrderingExpressions = new List(); if (orderingsToBeErased != null) { - var subquery = (SelectExpression)collectionJoinedInnerTable; // Ordering was present but erased so we add again - foreach (var ordering in orderingsToBeErased) + if (pushdownOccurredWhenJoining) { - innerOrderingExpressions.Add( - new OrderingExpression( - subquery.GenerateOuterColumn(collectionJoinedTableReference, ordering.Expression), - ordering.IsAscending)); + // We lift from inner subquery if pushdown occurred with ordering erased + var subquery = (SelectExpression)collectionJoinedInnerTable; + foreach (var ordering in orderingsToBeErased) + { + innerOrderingExpressions.Add( + new OrderingExpression( + subquery.GenerateOuterColumn(collectionJoinedTableReference, ordering.Expression), + ordering.IsAscending)); + } + } + else + { + // We copy from inner if pushdown did not happen but ordering was left behind when + // generating join + innerOrderingExpressions.AddRange(orderingsToBeErased); } } else { + // If orderings were not erased then they must be present in inner GetOrderingsFromInnerTable( collectionJoinedInnerTable, collectionJoinedTableReference, @@ -722,20 +733,58 @@ static Expression RemoveConvert(Expression expression) innerShaperExpression = innerSelectExpression.ApplyProjection( innerShaperExpression, shapedQueryExpression.ResultCardinality, querySplittingBehavior); - AddJoin(JoinType.OuterApply, ref innerSelectExpression); - var innerOrderingExpressions = new List(); - if (!GetOrderingsFromInnerTable( - innerSelectExpression._tables[0], - innerSelectExpression._tableReferences[0], - innerOrderingExpressions)) + var containsOrdering = innerSelectExpression.Orderings.Count > 0; + List? orderingsToBeErased = null; + if (containsOrdering + && innerSelectExpression.Limit == null + && innerSelectExpression.Offset == null) { - innerOrderingExpressions.AddRange(innerSelectExpression.Orderings); + orderingsToBeErased = innerSelectExpression.Orderings.ToList(); } + AddJoin(JoinType.OuterApply, ref innerSelectExpression, out var pushdownOccurredWhenJoining); - foreach (var ordering in innerOrderingExpressions) + // Copy over any nested ordering if there were any + if (containsOrdering) { - AppendOrdering(ordering.Update(MakeNullable(ordering.Expression, nullable: true))); + var collectionJoinedInnerTable = innerSelectExpression._tables[0]; + var collectionJoinedTableReference = innerSelectExpression._tableReferences[0]; + var innerOrderingExpressions = new List(); + if (orderingsToBeErased != null) + { + // Ordering was present but erased so we add again + if (pushdownOccurredWhenJoining) + { + // We lift from inner subquery if pushdown occurred with ordering erased + var subquery = (SelectExpression)collectionJoinedInnerTable; + foreach (var ordering in orderingsToBeErased) + { + innerOrderingExpressions.Add( + new OrderingExpression( + subquery.GenerateOuterColumn(collectionJoinedTableReference, ordering.Expression), + ordering.IsAscending)); + } + } + else + { + // We copy from inner if pushdown did not happen but ordering was left behind when + // generating join + innerOrderingExpressions.AddRange(orderingsToBeErased); + } + } + else + { + // If orderings were not erased then they must be present in inner + GetOrderingsFromInnerTable( + collectionJoinedInnerTable, + collectionJoinedTableReference, + innerOrderingExpressions); + } + + foreach (var ordering in innerOrderingExpressions) + { + AppendOrdering(ordering.Update(MakeNullable(ordering.Expression, nullable: true))); + } } innerShaperExpression = CopyProjectionToOuter(innerSelectExpression, innerShaperExpression); @@ -830,11 +879,13 @@ static Expression RemoveConvert(Expression expression) return shaperExpression; - bool GetOrderingsFromInnerTable( + void GetOrderingsFromInnerTable( TableExpressionBase tableExpressionBase, TableReferenceExpression tableReferenceExpression, List orderings) { + // If operation was converted to predicate join (inner/left join), + // then ordering will be in rownumber expression if (tableExpressionBase is SelectExpression joinedSubquery && joinedSubquery.Predicate != null && joinedSubquery.Tables.Count == 1 @@ -862,11 +913,9 @@ bool GetOrderingsFromInnerTable( rowNumberSubquery.GenerateOuterColumn(rowNumberSubqueryTableReference, ordering.Expression)), ordering.IsAscending)); } - - return true; } - - if (tableExpressionBase is SelectExpression collectionSelectExpression + // If operation remained apply then ordering will be in the subquery + else if (tableExpressionBase is SelectExpression collectionSelectExpression && collectionSelectExpression.Orderings.Count > 0) { foreach (var ordering in collectionSelectExpression.Orderings) @@ -876,11 +925,7 @@ bool GetOrderingsFromInnerTable( collectionSelectExpression.GenerateOuterColumn(tableReferenceExpression, ordering.Expression), ordering.IsAscending)); } - - return true; } - - return false; } Expression CopyProjectionToOuter(SelectExpression innerSelectExpression, Expression innerShaperExpression) @@ -1917,7 +1962,7 @@ private Expression AddJoin( Expression innerShaper, SqlExpression? joinPredicate = null) { - AddJoin(joinType, ref innerSelectExpression, joinPredicate); + AddJoin(joinType, ref innerSelectExpression, out _, joinPredicate); var transparentIdentifierType = TransparentIdentifierFactory.Create(outerShaper.Type, innerShaper.Type); var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); @@ -2023,8 +2068,10 @@ private Expression AddJoin( private void AddJoin( JoinType joinType, ref SelectExpression innerSelectExpression, + out bool innerPushdownOccurred, SqlExpression? joinPredicate = null) { + innerPushdownOccurred = false; // Try to convert Apply to normal join if (joinType == JoinType.CrossApply || joinType == JoinType.OuterApply) @@ -2099,7 +2146,9 @@ private void AddJoin( AddJoin( joinType == JoinType.CrossApply ? JoinType.InnerJoin : JoinType.LeftJoin, - ref innerSelectExpression, joinPredicate); + ref innerSelectExpression, + out innerPushdownOccurred, + joinPredicate); return; } @@ -2131,8 +2180,7 @@ private void AddJoin( joinPredicate = sqlRemappingVisitor.Remap(joinPredicate); } - if (innerSelectExpression.Orderings.Count > 0 - || innerSelectExpression.Limit != null + if (innerSelectExpression.Limit != null || innerSelectExpression.Offset != null || innerSelectExpression.IsDistinct || innerSelectExpression.Predicate != null @@ -2140,6 +2188,7 @@ private void AddJoin( || innerSelectExpression.GroupBy.Count > 0) { joinPredicate = innerSelectExpression.PushdownIntoSubqueryInternal().Remap(joinPredicate); + innerPushdownOccurred = true; } if (_identifier.Count > 0 @@ -2481,7 +2530,7 @@ public void AddInnerJoin(SelectExpression innerSelectExpression, SqlExpression j Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); Check.NotNull(joinPredicate, nameof(joinPredicate)); - AddJoin(JoinType.InnerJoin, ref innerSelectExpression, joinPredicate); + AddJoin(JoinType.InnerJoin, ref innerSelectExpression, out _, joinPredicate); } /// @@ -2494,7 +2543,7 @@ public void AddLeftJoin(SelectExpression innerSelectExpression, SqlExpression jo Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); Check.NotNull(joinPredicate, nameof(joinPredicate)); - AddJoin(JoinType.LeftJoin, ref innerSelectExpression, joinPredicate); + AddJoin(JoinType.LeftJoin, ref innerSelectExpression, out _, joinPredicate); } /// @@ -2505,7 +2554,7 @@ public void AddCrossJoin(SelectExpression innerSelectExpression) { Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - AddJoin(JoinType.CrossJoin, ref innerSelectExpression); + AddJoin(JoinType.CrossJoin, ref innerSelectExpression, out _); } /// @@ -2516,7 +2565,7 @@ public void AddCrossApply(SelectExpression innerSelectExpression) { Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - AddJoin(JoinType.CrossApply, ref innerSelectExpression); + AddJoin(JoinType.CrossApply, ref innerSelectExpression, out _); } /// @@ -2527,7 +2576,7 @@ public void AddOuterApply(SelectExpression innerSelectExpression) { Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - AddJoin(JoinType.OuterApply, ref innerSelectExpression); + AddJoin(JoinType.OuterApply, ref innerSelectExpression, out _); } /// diff --git a/test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs b/test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs index 247e0a29f34..41a827f6b06 100644 --- a/test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs +++ b/test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs @@ -96,11 +96,11 @@ public void AssertBaseline(string[] expected, bool assertOrder = true) const string indent = FileNewLine + " "; var newBaseLine = $@" AssertSql( - {string.Join("," + indent + "//" + indent, SqlStatements.Take(9).Select(sql => "@\"" + sql.Replace("\"", "\"\"") + "\""))}); + {string.Join("," + indent + "//" + indent, SqlStatements.Take(20).Select(sql => "@\"" + sql.Replace("\"", "\"\"") + "\""))}); "; - if (SqlStatements.Count > 9) + if (SqlStatements.Count > 20) { newBaseLine += "Output truncated."; } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs index 356ebcdac45..bc52794265e 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs @@ -1086,7 +1086,7 @@ public override async Task Select_subquery_single_nested_subquery(bool async) await base.Select_subquery_single_nested_subquery(async); AssertSql( - @"SELECT [l].[Id], [t0].[Id], [t1].[Id], [t0].[c] + @"SELECT [l].[Id], [t0].[Id], [l1].[Id], [t0].[c] FROM [LevelOne] AS [l] LEFT JOIN ( SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] @@ -1096,11 +1096,8 @@ FROM [LevelTwo] AS [l0] ) AS [t] WHERE [t].[row] <= 1 ) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] -LEFT JOIN ( - SELECT [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id] - FROM [LevelThree] AS [l1] -) AS [t1] ON [t0].[Id] = [t1].[OneToMany_Optional_Inverse3Id] -ORDER BY [l].[Id], [t0].[Id], [t1].[Id]"); +LEFT JOIN [LevelThree] AS [l1] ON [t0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t0].[Id], [l1].[Id]"); } public override async Task Select_subquery_single_nested_subquery2(bool async) @@ -1108,25 +1105,22 @@ public override async Task Select_subquery_single_nested_subquery2(bool async) await base.Select_subquery_single_nested_subquery2(async); AssertSql( - @"SELECT [l].[Id], [t2].[Id], [t2].[Id0], [t2].[Id1], [t2].[c] + @"SELECT [l].[Id], [t1].[Id], [t1].[Id0], [t1].[Id1], [t1].[c] FROM [LevelOne] AS [l] LEFT JOIN ( - SELECT [l0].[Id], [t0].[Id] AS [Id0], [t1].[Id] AS [Id1], [t0].[c], [l0].[OneToMany_Optional_Inverse2Id] + SELECT [l0].[Id], [t0].[Id] AS [Id0], [l1].[Id] AS [Id1], [t0].[c], [l0].[OneToMany_Optional_Inverse2Id] FROM [LevelTwo] AS [l0] LEFT JOIN ( SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse3Id] FROM ( - SELECT 1 AS [c], [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Optional_Inverse3Id] ORDER BY [l1].[Id]) AS [row] - FROM [LevelThree] AS [l1] + SELECT 1 AS [c], [l2].[Id], [l2].[OneToMany_Optional_Inverse3Id], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Optional_Inverse3Id] ORDER BY [l2].[Id]) AS [row] + FROM [LevelThree] AS [l2] ) AS [t] WHERE [t].[row] <= 1 ) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse3Id] - LEFT JOIN ( - SELECT [l2].[Id], [l2].[OneToMany_Optional_Inverse4Id] - FROM [LevelFour] AS [l2] - ) AS [t1] ON [t0].[Id] = [t1].[OneToMany_Optional_Inverse4Id] -) AS [t2] ON [l].[Id] = [t2].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t2].[Id], [t2].[Id0], [t2].[Id1]"); + LEFT JOIN [LevelFour] AS [l1] ON [t0].[Id] = [l1].[OneToMany_Optional_Inverse4Id] +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id0], [t1].[Id1]"); } public override async Task Filtered_include_basic_Where(bool async) @@ -1149,13 +1143,10 @@ public override async Task Filtered_include_OrderBy(bool async) await base.Filtered_include_OrderBy(async); AssertSql( - @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id] + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] FROM [LevelOne] AS [l] -LEFT JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] - FROM [LevelTwo] AS [l0] -) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t].[Name]"); +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [l0].[Name]"); } public override async Task Filtered_ThenInclude_OrderBy(bool async) @@ -1163,17 +1154,14 @@ public override async Task Filtered_ThenInclude_OrderBy(bool async) await base.Filtered_ThenInclude_OrderBy(async); AssertSql( - @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id] + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id] FROM [LevelOne] AS [l] LEFT JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [t].[Id] AS [Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name] AS [Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id] + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] FROM [LevelTwo] AS [l0] - LEFT JOIN ( - SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] - FROM [LevelThree] AS [l1] - ) AS [t] ON [l0].[Id] = [t].[OneToMany_Optional_Inverse3Id] -) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t0].[Id], [t0].[Name0]"); + LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Name0]"); } public override async Task Filtered_include_ThenInclude_OrderBy(bool async) @@ -1181,17 +1169,14 @@ public override async Task Filtered_include_ThenInclude_OrderBy(bool async) await base.Filtered_include_ThenInclude_OrderBy(async); AssertSql( - @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id] + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id] FROM [LevelOne] AS [l] LEFT JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [t].[Id] AS [Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name] AS [Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id] + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] FROM [LevelTwo] AS [l0] - LEFT JOIN ( - SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] - FROM [LevelThree] AS [l1] - ) AS [t] ON [l0].[Id] = [t].[OneToMany_Optional_Inverse3Id] -) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t0].[Name], [t0].[Id], [t0].[Name0] DESC"); + LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Name], [t].[Id], [t].[Name0] DESC"); } public override async Task Filtered_include_basic_OrderBy_Take(bool async) @@ -1263,7 +1248,7 @@ FROM [LevelTwo] AS [l0] ) AS [t] WHERE 1 < [t].[row] ) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); +ORDER BY [l].[Id]"); } public override async Task Filtered_include_Take_without_OrderBy(bool async) @@ -1281,7 +1266,7 @@ FROM [LevelTwo] AS [l0] ) AS [t] WHERE [t].[row] <= 1 ) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); +ORDER BY [l].[Id]"); } public override async Task Filtered_include_on_ThenInclude(bool async) @@ -2154,7 +2139,7 @@ FROM [LevelTwo] AS [l0] ) AS [t] WHERE [t].[row] <= 50 ) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); +ORDER BY [l].[Id]"); } public override async Task FirstOrDefault_with_predicate_on_correlated_collection_in_projection(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs index 509624571d8..eadf0ec71c3 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs @@ -47,13 +47,10 @@ public override async Task Filtered_include_OrderBy(bool async) FROM [LevelOne] AS [l] ORDER BY [l].[Id]", // - @"SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [l].[Id] + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l].[Id] FROM [LevelOne] AS [l] -INNER JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] - FROM [LevelTwo] AS [l0] -) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t].[Name]"); +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [l0].[Name]"); } public override async Task Filtered_ThenInclude_OrderBy(bool async) @@ -70,14 +67,11 @@ FROM [LevelOne] AS [l] INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l].[Id], [l0].[Id]", // - @"SELECT [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [l].[Id], [l0].[Id] + @"SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l].[Id], [l0].[Id] FROM [LevelOne] AS [l] INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] -INNER JOIN ( - SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] - FROM [LevelThree] AS [l1] -) AS [t] ON [l0].[Id] = [t].[OneToMany_Optional_Inverse3Id] -ORDER BY [l].[Id], [l0].[Id], [t].[Name]"); +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Name]"); } public override async Task Filtered_include_ThenInclude_OrderBy(bool async) @@ -89,25 +83,16 @@ public override async Task Filtered_include_ThenInclude_OrderBy(bool async) FROM [LevelOne] AS [l] ORDER BY [l].[Id]", // - @"SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [l].[Id] + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l].[Id] FROM [LevelOne] AS [l] -INNER JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] - FROM [LevelTwo] AS [l0] -) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] -ORDER BY [l].[Id], [t].[Name], [t].[Id]", +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [l0].[Name], [l0].[Id]", // - @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [l].[Id], [t].[Id] + @"SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l].[Id], [l0].[Id] FROM [LevelOne] AS [l] -INNER JOIN ( - SELECT [l0].[Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id] - FROM [LevelTwo] AS [l0] -) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] -INNER JOIN ( - SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] - FROM [LevelThree] AS [l1] -) AS [t0] ON [t].[Id] = [t0].[OneToMany_Optional_Inverse3Id] -ORDER BY [l].[Id], [t].[Name], [t].[Id], [t0].[Name] DESC"); +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Name], [l0].[Id], [l1].[Name] DESC"); } public override async Task Filtered_include_basic_OrderBy_Take(bool async) @@ -1197,7 +1182,7 @@ FROM [LevelTwo] AS [l0] ) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] ORDER BY [l].[Id], [t0].[Id]", // - @"SELECT [t1].[Id], [l].[Id], [t0].[Id] + @"SELECT [l1].[Id], [l].[Id], [t0].[Id] FROM [LevelOne] AS [l] LEFT JOIN ( SELECT [t].[Id], [t].[OneToMany_Optional_Inverse2Id] @@ -1207,11 +1192,8 @@ FROM [LevelTwo] AS [l0] ) AS [t] WHERE [t].[row] <= 1 ) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] -INNER JOIN ( - SELECT [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id] - FROM [LevelThree] AS [l1] -) AS [t1] ON [t0].[Id] = [t1].[OneToMany_Optional_Inverse3Id] -ORDER BY [l].[Id], [t0].[Id], [t1].[Id]"); +INNER JOIN [LevelThree] AS [l1] ON [t0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t0].[Id], [l1].[Id]"); } public override async Task Select_subquery_single_nested_subquery2(bool async) @@ -1223,41 +1205,32 @@ public override async Task Select_subquery_single_nested_subquery2(bool async) FROM [LevelOne] AS [l] ORDER BY [l].[Id]", // - @"SELECT [l].[Id], [t].[Id], [t0].[Id], [t0].[c] + @"SELECT [l].[Id], [l0].[Id], [t0].[Id], [t0].[c] FROM [LevelOne] AS [l] -INNER JOIN ( - SELECT [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id] - FROM [LevelTwo] AS [l0] -) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] LEFT JOIN ( - SELECT [t1].[c], [t1].[Id], [t1].[OneToMany_Optional_Inverse3Id] + SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse3Id] FROM ( SELECT 1 AS [c], [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Optional_Inverse3Id] ORDER BY [l1].[Id]) AS [row] FROM [LevelThree] AS [l1] - ) AS [t1] - WHERE [t1].[row] <= 1 -) AS [t0] ON [t].[Id] = [t0].[OneToMany_Optional_Inverse3Id] -ORDER BY [l].[Id], [t].[Id], [t0].[Id]", + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [t0].[Id]", // - @"SELECT [t2].[Id], [l].[Id], [t].[Id], [t0].[Id] + @"SELECT [l2].[Id], [l].[Id], [l0].[Id], [t0].[Id] FROM [LevelOne] AS [l] -INNER JOIN ( - SELECT [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id] - FROM [LevelTwo] AS [l0] -) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] LEFT JOIN ( - SELECT [t1].[Id], [t1].[OneToMany_Optional_Inverse3Id] + SELECT [t].[Id], [t].[OneToMany_Optional_Inverse3Id] FROM ( SELECT [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Optional_Inverse3Id] ORDER BY [l1].[Id]) AS [row] FROM [LevelThree] AS [l1] - ) AS [t1] - WHERE [t1].[row] <= 1 -) AS [t0] ON [t].[Id] = [t0].[OneToMany_Optional_Inverse3Id] -INNER JOIN ( - SELECT [l2].[Id], [l2].[OneToMany_Optional_Inverse4Id] - FROM [LevelFour] AS [l2] -) AS [t2] ON [t0].[Id] = [t2].[OneToMany_Optional_Inverse4Id] -ORDER BY [l].[Id], [t].[Id], [t0].[Id], [t2].[Id]"); + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse3Id] +INNER JOIN [LevelFour] AS [l2] ON [t0].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [t0].[Id], [l2].[Id]"); } public override async Task Queryable_in_subquery_works_when_final_projection_is_List(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs index c4b4a4c94c0..2666d267f99 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs @@ -2006,16 +2006,13 @@ public override async Task GroupJoin_on_a_subquery_containing_another_GroupJoin_ SELECT [l1].[Name] FROM ( - SELECT TOP(@__p_0) [l].[Id], [t].[Level1_Optional_Id] + SELECT TOP(@__p_0) [l].[Id], [l0].[Level1_Optional_Id] FROM [LevelOne] AS [l] - LEFT JOIN ( - SELECT [l0].[Level1_Optional_Id] - FROM [LevelTwo] AS [l0] - ) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] ORDER BY [l].[Id] -) AS [t0] -LEFT JOIN [LevelOne] AS [l1] ON [t0].[Level1_Optional_Id] = [l1].[Id] -ORDER BY [t0].[Id]"); +) AS [t] +LEFT JOIN [LevelOne] AS [l1] ON [t].[Level1_Optional_Id] = [l1].[Id] +ORDER BY [t].[Id]"); } public override async Task GroupJoin_on_left_side_being_a_subquery(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysQuerySqlServerTest.cs index 2a77a8c098d..764b1fe8dc6 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysQuerySqlServerTest.cs @@ -49,17 +49,11 @@ public override async Task Projecting_multiple_collections_with_ordering_same_le await base.Projecting_multiple_collections_with_ordering_same_level(async); AssertSql( - @"SELECT [c].[Name], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2], [t].[Date], [t].[Level1_Optional_Id1], [t].[Level1_Optional_Id2], [t].[Level1_Required_Id1], [t].[Level1_Required_Id2], [t].[Name], [t].[OneToMany_Optional_Inverse2Id1], [t].[OneToMany_Optional_Inverse2Id2], [t].[OneToMany_Optional_Self_Inverse2Id1], [t].[OneToMany_Optional_Self_Inverse2Id2], [t].[OneToMany_Required_Inverse2Id1], [t].[OneToMany_Required_Inverse2Id2], [t].[OneToMany_Required_Self_Inverse2Id1], [t].[OneToMany_Required_Self_Inverse2Id2], [t].[OneToOne_Optional_PK_Inverse2Id1], [t].[OneToOne_Optional_PK_Inverse2Id2], [t].[OneToOne_Optional_Self2Id1], [t].[OneToOne_Optional_Self2Id2], [t0].[Id1], [t0].[Id2], [t0].[Date], [t0].[Level1_Optional_Id1], [t0].[Level1_Optional_Id2], [t0].[Level1_Required_Id1], [t0].[Level1_Required_Id2], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id1], [t0].[OneToMany_Optional_Inverse2Id2], [t0].[OneToMany_Optional_Self_Inverse2Id1], [t0].[OneToMany_Optional_Self_Inverse2Id2], [t0].[OneToMany_Required_Inverse2Id1], [t0].[OneToMany_Required_Inverse2Id2], [t0].[OneToMany_Required_Self_Inverse2Id1], [t0].[OneToMany_Required_Self_Inverse2Id2], [t0].[OneToOne_Optional_PK_Inverse2Id1], [t0].[OneToOne_Optional_PK_Inverse2Id2], [t0].[OneToOne_Optional_Self2Id1], [t0].[OneToOne_Optional_Self2Id2] + @"SELECT [c].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2], [c1].[Id1], [c1].[Id2], [c1].[Date], [c1].[Level1_Optional_Id1], [c1].[Level1_Optional_Id2], [c1].[Level1_Required_Id1], [c1].[Level1_Required_Id2], [c1].[Name], [c1].[OneToMany_Optional_Inverse2Id1], [c1].[OneToMany_Optional_Inverse2Id2], [c1].[OneToMany_Optional_Self_Inverse2Id1], [c1].[OneToMany_Optional_Self_Inverse2Id2], [c1].[OneToMany_Required_Inverse2Id1], [c1].[OneToMany_Required_Inverse2Id2], [c1].[OneToMany_Required_Self_Inverse2Id1], [c1].[OneToMany_Required_Self_Inverse2Id2], [c1].[OneToOne_Optional_PK_Inverse2Id1], [c1].[OneToOne_Optional_PK_Inverse2Id2], [c1].[OneToOne_Optional_Self2Id1], [c1].[OneToOne_Optional_Self2Id2] FROM [CompositeOnes] AS [c] -LEFT JOIN ( - SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Optional_Inverse2Id2]) -LEFT JOIN ( - SELECT [c1].[Id1], [c1].[Id2], [c1].[Date], [c1].[Level1_Optional_Id1], [c1].[Level1_Optional_Id2], [c1].[Level1_Required_Id1], [c1].[Level1_Required_Id2], [c1].[Name], [c1].[OneToMany_Optional_Inverse2Id1], [c1].[OneToMany_Optional_Inverse2Id2], [c1].[OneToMany_Optional_Self_Inverse2Id1], [c1].[OneToMany_Optional_Self_Inverse2Id2], [c1].[OneToMany_Required_Inverse2Id1], [c1].[OneToMany_Required_Inverse2Id2], [c1].[OneToMany_Required_Self_Inverse2Id1], [c1].[OneToMany_Required_Self_Inverse2Id2], [c1].[OneToOne_Optional_PK_Inverse2Id1], [c1].[OneToOne_Optional_PK_Inverse2Id2], [c1].[OneToOne_Optional_Self2Id1], [c1].[OneToOne_Optional_Self2Id2] - FROM [CompositeTwos] AS [c1] -) AS [t0] ON ([c].[Id1] = [t0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t0].[OneToMany_Required_Inverse2Id2]) -ORDER BY [c].[Id1], [c].[Id2], [t].[Id2], [t].[Id1], [t0].[Name] DESC, [t0].[Id1]"); +LEFT JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Optional_Inverse2Id2]) +LEFT JOIN [CompositeTwos] AS [c1] ON ([c].[Id1] = [c1].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c1].[OneToMany_Required_Inverse2Id2]) +ORDER BY [c].[Id1], [c].[Id2], [c0].[Id2], [c0].[Id1], [c1].[Name] DESC, [c1].[Id1]"); } public override async Task Projecting_multiple_collections_with_ordering_same_level_top_level_ordering(bool async) @@ -67,17 +61,11 @@ public override async Task Projecting_multiple_collections_with_ordering_same_le await base.Projecting_multiple_collections_with_ordering_same_level_top_level_ordering(async); AssertSql( - @"SELECT [c].[Name], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2], [t].[Date], [t].[Level1_Optional_Id1], [t].[Level1_Optional_Id2], [t].[Level1_Required_Id1], [t].[Level1_Required_Id2], [t].[Name], [t].[OneToMany_Optional_Inverse2Id1], [t].[OneToMany_Optional_Inverse2Id2], [t].[OneToMany_Optional_Self_Inverse2Id1], [t].[OneToMany_Optional_Self_Inverse2Id2], [t].[OneToMany_Required_Inverse2Id1], [t].[OneToMany_Required_Inverse2Id2], [t].[OneToMany_Required_Self_Inverse2Id1], [t].[OneToMany_Required_Self_Inverse2Id2], [t].[OneToOne_Optional_PK_Inverse2Id1], [t].[OneToOne_Optional_PK_Inverse2Id2], [t].[OneToOne_Optional_Self2Id1], [t].[OneToOne_Optional_Self2Id2], [t0].[Id1], [t0].[Id2], [t0].[Date], [t0].[Level1_Optional_Id1], [t0].[Level1_Optional_Id2], [t0].[Level1_Required_Id1], [t0].[Level1_Required_Id2], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id1], [t0].[OneToMany_Optional_Inverse2Id2], [t0].[OneToMany_Optional_Self_Inverse2Id1], [t0].[OneToMany_Optional_Self_Inverse2Id2], [t0].[OneToMany_Required_Inverse2Id1], [t0].[OneToMany_Required_Inverse2Id2], [t0].[OneToMany_Required_Self_Inverse2Id1], [t0].[OneToMany_Required_Self_Inverse2Id2], [t0].[OneToOne_Optional_PK_Inverse2Id1], [t0].[OneToOne_Optional_PK_Inverse2Id2], [t0].[OneToOne_Optional_Self2Id1], [t0].[OneToOne_Optional_Self2Id2] + @"SELECT [c].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2], [c1].[Id1], [c1].[Id2], [c1].[Date], [c1].[Level1_Optional_Id1], [c1].[Level1_Optional_Id2], [c1].[Level1_Required_Id1], [c1].[Level1_Required_Id2], [c1].[Name], [c1].[OneToMany_Optional_Inverse2Id1], [c1].[OneToMany_Optional_Inverse2Id2], [c1].[OneToMany_Optional_Self_Inverse2Id1], [c1].[OneToMany_Optional_Self_Inverse2Id2], [c1].[OneToMany_Required_Inverse2Id1], [c1].[OneToMany_Required_Inverse2Id2], [c1].[OneToMany_Required_Self_Inverse2Id1], [c1].[OneToMany_Required_Self_Inverse2Id2], [c1].[OneToOne_Optional_PK_Inverse2Id1], [c1].[OneToOne_Optional_PK_Inverse2Id2], [c1].[OneToOne_Optional_Self2Id1], [c1].[OneToOne_Optional_Self2Id2] FROM [CompositeOnes] AS [c] -LEFT JOIN ( - SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Optional_Inverse2Id2]) -LEFT JOIN ( - SELECT [c1].[Id1], [c1].[Id2], [c1].[Date], [c1].[Level1_Optional_Id1], [c1].[Level1_Optional_Id2], [c1].[Level1_Required_Id1], [c1].[Level1_Required_Id2], [c1].[Name], [c1].[OneToMany_Optional_Inverse2Id1], [c1].[OneToMany_Optional_Inverse2Id2], [c1].[OneToMany_Optional_Self_Inverse2Id1], [c1].[OneToMany_Optional_Self_Inverse2Id2], [c1].[OneToMany_Required_Inverse2Id1], [c1].[OneToMany_Required_Inverse2Id2], [c1].[OneToMany_Required_Self_Inverse2Id1], [c1].[OneToMany_Required_Self_Inverse2Id2], [c1].[OneToOne_Optional_PK_Inverse2Id1], [c1].[OneToOne_Optional_PK_Inverse2Id2], [c1].[OneToOne_Optional_Self2Id1], [c1].[OneToOne_Optional_Self2Id2] - FROM [CompositeTwos] AS [c1] -) AS [t0] ON ([c].[Id1] = [t0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t0].[OneToMany_Required_Inverse2Id2]) -ORDER BY [c].[Id2], [c].[Id1], [t].[Id2], [t].[Id1], [t0].[Name] DESC, [t0].[Id1]"); +LEFT JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Optional_Inverse2Id2]) +LEFT JOIN [CompositeTwos] AS [c1] ON ([c].[Id1] = [c1].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c1].[OneToMany_Required_Inverse2Id2]) +ORDER BY [c].[Id2], [c].[Id1], [c0].[Id2], [c0].[Id1], [c1].[Name] DESC, [c1].[Id1]"); } public override async Task Projecting_collections_multi_level(bool async) @@ -85,17 +73,14 @@ public override async Task Projecting_collections_multi_level(bool async) await base.Projecting_collections_multi_level(async); AssertSql( - @"SELECT [c].[Name], [c].[Id1], [c].[Id2], [t0].[Name], [t0].[Id1], [t0].[Id2], [t0].[Id10], [t0].[Id20], [t0].[Level2_Optional_Id1], [t0].[Level2_Optional_Id2], [t0].[Level2_Required_Id1], [t0].[Level2_Required_Id2], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id1], [t0].[OneToMany_Optional_Inverse3Id2], [t0].[OneToMany_Optional_Self_Inverse3Id1], [t0].[OneToMany_Optional_Self_Inverse3Id2], [t0].[OneToMany_Required_Inverse3Id1], [t0].[OneToMany_Required_Inverse3Id2], [t0].[OneToMany_Required_Self_Inverse3Id1], [t0].[OneToMany_Required_Self_Inverse3Id2], [t0].[OneToOne_Optional_PK_Inverse3Id1], [t0].[OneToOne_Optional_PK_Inverse3Id2], [t0].[OneToOne_Optional_Self3Id1], [t0].[OneToOne_Optional_Self3Id2] + @"SELECT [c].[Name], [c].[Id1], [c].[Id2], [t].[Name], [t].[Id1], [t].[Id2], [t].[Id10], [t].[Id20], [t].[Level2_Optional_Id1], [t].[Level2_Optional_Id2], [t].[Level2_Required_Id1], [t].[Level2_Required_Id2], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id1], [t].[OneToMany_Optional_Inverse3Id2], [t].[OneToMany_Optional_Self_Inverse3Id1], [t].[OneToMany_Optional_Self_Inverse3Id2], [t].[OneToMany_Required_Inverse3Id1], [t].[OneToMany_Required_Inverse3Id2], [t].[OneToMany_Required_Self_Inverse3Id1], [t].[OneToMany_Required_Self_Inverse3Id2], [t].[OneToOne_Optional_PK_Inverse3Id1], [t].[OneToOne_Optional_PK_Inverse3Id2], [t].[OneToOne_Optional_Self3Id1], [t].[OneToOne_Optional_Self3Id2] FROM [CompositeOnes] AS [c] LEFT JOIN ( - SELECT [c0].[Name], [c0].[Id1], [c0].[Id2], [t].[Id1] AS [Id10], [t].[Id2] AS [Id20], [t].[Level2_Optional_Id1], [t].[Level2_Optional_Id2], [t].[Level2_Required_Id1], [t].[Level2_Required_Id2], [t].[Name] AS [Name0], [t].[OneToMany_Optional_Inverse3Id1], [t].[OneToMany_Optional_Inverse3Id2], [t].[OneToMany_Optional_Self_Inverse3Id1], [t].[OneToMany_Optional_Self_Inverse3Id2], [t].[OneToMany_Required_Inverse3Id1], [t].[OneToMany_Required_Inverse3Id2], [t].[OneToMany_Required_Self_Inverse3Id1], [t].[OneToMany_Required_Self_Inverse3Id2], [t].[OneToOne_Optional_PK_Inverse3Id1], [t].[OneToOne_Optional_PK_Inverse3Id2], [t].[OneToOne_Optional_Self3Id1], [t].[OneToOne_Optional_Self3Id2], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2] + SELECT [c0].[Name], [c0].[Id1], [c0].[Id2], [c1].[Id1] AS [Id10], [c1].[Id2] AS [Id20], [c1].[Level2_Optional_Id1], [c1].[Level2_Optional_Id2], [c1].[Level2_Required_Id1], [c1].[Level2_Required_Id2], [c1].[Name] AS [Name0], [c1].[OneToMany_Optional_Inverse3Id1], [c1].[OneToMany_Optional_Inverse3Id2], [c1].[OneToMany_Optional_Self_Inverse3Id1], [c1].[OneToMany_Optional_Self_Inverse3Id2], [c1].[OneToMany_Required_Inverse3Id1], [c1].[OneToMany_Required_Inverse3Id2], [c1].[OneToMany_Required_Self_Inverse3Id1], [c1].[OneToMany_Required_Self_Inverse3Id2], [c1].[OneToOne_Optional_PK_Inverse3Id1], [c1].[OneToOne_Optional_PK_Inverse3Id2], [c1].[OneToOne_Optional_Self3Id1], [c1].[OneToOne_Optional_Self3Id2], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2] FROM [CompositeTwos] AS [c0] - LEFT JOIN ( - SELECT [c1].[Id1], [c1].[Id2], [c1].[Level2_Optional_Id1], [c1].[Level2_Optional_Id2], [c1].[Level2_Required_Id1], [c1].[Level2_Required_Id2], [c1].[Name], [c1].[OneToMany_Optional_Inverse3Id1], [c1].[OneToMany_Optional_Inverse3Id2], [c1].[OneToMany_Optional_Self_Inverse3Id1], [c1].[OneToMany_Optional_Self_Inverse3Id2], [c1].[OneToMany_Required_Inverse3Id1], [c1].[OneToMany_Required_Inverse3Id2], [c1].[OneToMany_Required_Self_Inverse3Id1], [c1].[OneToMany_Required_Self_Inverse3Id2], [c1].[OneToOne_Optional_PK_Inverse3Id1], [c1].[OneToOne_Optional_PK_Inverse3Id2], [c1].[OneToOne_Optional_Self3Id1], [c1].[OneToOne_Optional_Self3Id2] - FROM [CompositeThrees] AS [c1] - ) AS [t] ON ([c0].[Id1] = [t].[OneToMany_Required_Inverse3Id1]) AND ([c0].[Id2] = [t].[OneToMany_Required_Inverse3Id2]) -) AS [t0] ON ([c].[Id1] = [t0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [t0].[OneToMany_Optional_Inverse2Id2]) -ORDER BY [c].[Id2], [c].[Id1], [t0].[Id2], [t0].[Id1], [t0].[Id20] DESC"); + LEFT JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Required_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Required_Inverse3Id2]) +) AS [t] ON ([c].[Id1] = [t].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Optional_Inverse2Id2]) +ORDER BY [c].[Id2], [c].[Id1], [t].[Id2], [t].[Id1], [t].[Id20] DESC"); } public override async Task Projecting_multiple_collections_on_multiple_levels_no_explicit_ordering(bool async) @@ -173,13 +158,10 @@ LEFT JOIN [CompositeFours] AS [c9] ON ([c8].[Id1] = [c9].[OneToMany_Required_Inv LEFT JOIN [CompositeFours] AS [c10] ON ([c8].[Id1] = [c10].[OneToMany_Optional_Inverse4Id1]) AND ([c8].[Id2] = [c10].[OneToMany_Optional_Inverse4Id2]) ) AS [t3] ON ([c7].[Id1] = [t3].[OneToMany_Optional_Inverse3Id1]) AND ([c7].[Id2] = [t3].[OneToMany_Optional_Inverse3Id2]) LEFT JOIN ( - SELECT [c11].[Name], [c11].[Id1], [c11].[Id2], [c12].[Id1] AS [Id10], [c12].[Id2] AS [Id20], [c12].[Level3_Optional_Id1], [c12].[Level3_Optional_Id2], [c12].[Level3_Required_Id1], [c12].[Level3_Required_Id2], [c12].[Name] AS [Name0], [c12].[OneToMany_Optional_Inverse4Id1], [c12].[OneToMany_Optional_Inverse4Id2], [c12].[OneToMany_Optional_Self_Inverse4Id1], [c12].[OneToMany_Optional_Self_Inverse4Id2], [c12].[OneToMany_Required_Inverse4Id1], [c12].[OneToMany_Required_Inverse4Id2], [c12].[OneToMany_Required_Self_Inverse4Id1], [c12].[OneToMany_Required_Self_Inverse4Id2], [c12].[OneToOne_Optional_PK_Inverse4Id1], [c12].[OneToOne_Optional_PK_Inverse4Id2], [c12].[OneToOne_Optional_Self4Id1], [c12].[OneToOne_Optional_Self4Id2], [t5].[Id1] AS [Id11], [t5].[Id2] AS [Id21], [t5].[Level3_Optional_Id1] AS [Level3_Optional_Id10], [t5].[Level3_Optional_Id2] AS [Level3_Optional_Id20], [t5].[Level3_Required_Id1] AS [Level3_Required_Id10], [t5].[Level3_Required_Id2] AS [Level3_Required_Id20], [t5].[Name] AS [Name1], [t5].[OneToMany_Optional_Inverse4Id1] AS [OneToMany_Optional_Inverse4Id10], [t5].[OneToMany_Optional_Inverse4Id2] AS [OneToMany_Optional_Inverse4Id20], [t5].[OneToMany_Optional_Self_Inverse4Id1] AS [OneToMany_Optional_Self_Inverse4Id10], [t5].[OneToMany_Optional_Self_Inverse4Id2] AS [OneToMany_Optional_Self_Inverse4Id20], [t5].[OneToMany_Required_Inverse4Id1] AS [OneToMany_Required_Inverse4Id10], [t5].[OneToMany_Required_Inverse4Id2] AS [OneToMany_Required_Inverse4Id20], [t5].[OneToMany_Required_Self_Inverse4Id1] AS [OneToMany_Required_Self_Inverse4Id10], [t5].[OneToMany_Required_Self_Inverse4Id2] AS [OneToMany_Required_Self_Inverse4Id20], [t5].[OneToOne_Optional_PK_Inverse4Id1] AS [OneToOne_Optional_PK_Inverse4Id10], [t5].[OneToOne_Optional_PK_Inverse4Id2] AS [OneToOne_Optional_PK_Inverse4Id20], [t5].[OneToOne_Optional_Self4Id1] AS [OneToOne_Optional_Self4Id10], [t5].[OneToOne_Optional_Self4Id2] AS [OneToOne_Optional_Self4Id20], [t5].[c], [c11].[OneToMany_Optional_Inverse3Id1], [c11].[OneToMany_Optional_Inverse3Id2] + SELECT [c11].[Name], [c11].[Id1], [c11].[Id2], [c12].[Id1] AS [Id10], [c12].[Id2] AS [Id20], [c12].[Level3_Optional_Id1], [c12].[Level3_Optional_Id2], [c12].[Level3_Required_Id1], [c12].[Level3_Required_Id2], [c12].[Name] AS [Name0], [c12].[OneToMany_Optional_Inverse4Id1], [c12].[OneToMany_Optional_Inverse4Id2], [c12].[OneToMany_Optional_Self_Inverse4Id1], [c12].[OneToMany_Optional_Self_Inverse4Id2], [c12].[OneToMany_Required_Inverse4Id1], [c12].[OneToMany_Required_Inverse4Id2], [c12].[OneToMany_Required_Self_Inverse4Id1], [c12].[OneToMany_Required_Self_Inverse4Id2], [c12].[OneToOne_Optional_PK_Inverse4Id1], [c12].[OneToOne_Optional_PK_Inverse4Id2], [c12].[OneToOne_Optional_Self4Id1], [c12].[OneToOne_Optional_Self4Id2], [c13].[Id1] AS [Id11], [c13].[Id2] AS [Id21], [c13].[Level3_Optional_Id1] AS [Level3_Optional_Id10], [c13].[Level3_Optional_Id2] AS [Level3_Optional_Id20], [c13].[Level3_Required_Id1] AS [Level3_Required_Id10], [c13].[Level3_Required_Id2] AS [Level3_Required_Id20], [c13].[Name] AS [Name1], [c13].[OneToMany_Optional_Inverse4Id1] AS [OneToMany_Optional_Inverse4Id10], [c13].[OneToMany_Optional_Inverse4Id2] AS [OneToMany_Optional_Inverse4Id20], [c13].[OneToMany_Optional_Self_Inverse4Id1] AS [OneToMany_Optional_Self_Inverse4Id10], [c13].[OneToMany_Optional_Self_Inverse4Id2] AS [OneToMany_Optional_Self_Inverse4Id20], [c13].[OneToMany_Required_Inverse4Id1] AS [OneToMany_Required_Inverse4Id10], [c13].[OneToMany_Required_Inverse4Id2] AS [OneToMany_Required_Inverse4Id20], [c13].[OneToMany_Required_Self_Inverse4Id1] AS [OneToMany_Required_Self_Inverse4Id10], [c13].[OneToMany_Required_Self_Inverse4Id2] AS [OneToMany_Required_Self_Inverse4Id20], [c13].[OneToOne_Optional_PK_Inverse4Id1] AS [OneToOne_Optional_PK_Inverse4Id10], [c13].[OneToOne_Optional_PK_Inverse4Id2] AS [OneToOne_Optional_PK_Inverse4Id20], [c13].[OneToOne_Optional_Self4Id1] AS [OneToOne_Optional_Self4Id10], [c13].[OneToOne_Optional_Self4Id2] AS [OneToOne_Optional_Self4Id20], [c13].[Id1] + CAST([c13].[Id2] AS nvarchar(450)) AS [c], [c11].[OneToMany_Optional_Inverse3Id1], [c11].[OneToMany_Optional_Inverse3Id2] FROM [CompositeThrees] AS [c11] LEFT JOIN [CompositeFours] AS [c12] ON ([c11].[Id1] = [c12].[OneToMany_Optional_Inverse4Id1]) AND ([c11].[Id2] = [c12].[OneToMany_Optional_Inverse4Id2]) - LEFT JOIN ( - SELECT [c13].[Id1], [c13].[Id2], [c13].[Level3_Optional_Id1], [c13].[Level3_Optional_Id2], [c13].[Level3_Required_Id1], [c13].[Level3_Required_Id2], [c13].[Name], [c13].[OneToMany_Optional_Inverse4Id1], [c13].[OneToMany_Optional_Inverse4Id2], [c13].[OneToMany_Optional_Self_Inverse4Id1], [c13].[OneToMany_Optional_Self_Inverse4Id2], [c13].[OneToMany_Required_Inverse4Id1], [c13].[OneToMany_Required_Inverse4Id2], [c13].[OneToMany_Required_Self_Inverse4Id1], [c13].[OneToMany_Required_Self_Inverse4Id2], [c13].[OneToOne_Optional_PK_Inverse4Id1], [c13].[OneToOne_Optional_PK_Inverse4Id2], [c13].[OneToOne_Optional_Self4Id1], [c13].[OneToOne_Optional_Self4Id2], [c13].[Id1] + CAST([c13].[Id2] AS nvarchar(450)) AS [c] - FROM [CompositeFours] AS [c13] - ) AS [t5] ON ([c11].[Id1] = [t5].[OneToMany_Required_Inverse4Id1]) AND ([c11].[Id2] = [t5].[OneToMany_Required_Inverse4Id2]) + LEFT JOIN [CompositeFours] AS [c13] ON ([c11].[Id1] = [c13].[OneToMany_Required_Inverse4Id1]) AND ([c11].[Id2] = [c13].[OneToMany_Required_Inverse4Id2]) ) AS [t4] ON ([c7].[Id1] = [t4].[OneToMany_Optional_Inverse3Id1]) AND ([c7].[Id2] = [t4].[OneToMany_Optional_Inverse3Id2]) ) AS [t2] ON ([c].[Id1] = [t2].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t2].[OneToMany_Required_Inverse2Id2]) ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [t1].[Id1], [t1].[Id2], [t1].[Id20] DESC, [t1].[Id10] DESC, [t1].[Id100], [t1].[Id200], [t1].[Id11], [t1].[Id21], [t1].[Id12], [t1].[Id22], [t1].[Id101], [t1].[Id201], [t1].[Id110], [t1].[Id210], [t2].[c], [t2].[Id1], [t2].[Id2], [t2].[Id10], [t2].[Id20], [t2].[Id100], [t2].[Id200], [t2].[Id11], [t2].[Id21], [t2].[Id12], [t2].[Id22], [t2].[Id101], [t2].[Id201], [t2].[c0] DESC, [t2].[Id110]"); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysSplitQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysSplitQuerySqlServerTest.cs index dad125a5f8d..39767153cbd 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysSplitQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/CompositeKeysSplitQuerySqlServerTest.cs @@ -29,25 +29,16 @@ public override async Task Projecting_collections_multi_level(bool async) FROM [CompositeOnes] AS [c] ORDER BY [c].[Id2], [c].[Id1]", // - @"SELECT [t].[Name], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2] -FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Name], [c0].[Id1], [c0].[Id2], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Optional_Inverse2Id2]) -ORDER BY [c].[Id2], [c].[Id1], [t].[Id2], [t].[Id1]", - // - @"SELECT [t0].[Id1], [t0].[Id2], [t0].[Level2_Optional_Id1], [t0].[Level2_Optional_Id2], [t0].[Level2_Required_Id1], [t0].[Level2_Required_Id2], [t0].[Name], [t0].[OneToMany_Optional_Inverse3Id1], [t0].[OneToMany_Optional_Inverse3Id2], [t0].[OneToMany_Optional_Self_Inverse3Id1], [t0].[OneToMany_Optional_Self_Inverse3Id2], [t0].[OneToMany_Required_Inverse3Id1], [t0].[OneToMany_Required_Inverse3Id2], [t0].[OneToMany_Required_Self_Inverse3Id1], [t0].[OneToMany_Required_Self_Inverse3Id2], [t0].[OneToOne_Optional_PK_Inverse3Id1], [t0].[OneToOne_Optional_PK_Inverse3Id2], [t0].[OneToOne_Optional_Self3Id1], [t0].[OneToOne_Optional_Self3Id2], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2] -FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Optional_Inverse2Id2]) -INNER JOIN ( - SELECT [c1].[Id1], [c1].[Id2], [c1].[Level2_Optional_Id1], [c1].[Level2_Optional_Id2], [c1].[Level2_Required_Id1], [c1].[Level2_Required_Id2], [c1].[Name], [c1].[OneToMany_Optional_Inverse3Id1], [c1].[OneToMany_Optional_Inverse3Id2], [c1].[OneToMany_Optional_Self_Inverse3Id1], [c1].[OneToMany_Optional_Self_Inverse3Id2], [c1].[OneToMany_Required_Inverse3Id1], [c1].[OneToMany_Required_Inverse3Id2], [c1].[OneToMany_Required_Self_Inverse3Id1], [c1].[OneToMany_Required_Self_Inverse3Id2], [c1].[OneToOne_Optional_PK_Inverse3Id1], [c1].[OneToOne_Optional_PK_Inverse3Id2], [c1].[OneToOne_Optional_Self3Id1], [c1].[OneToOne_Optional_Self3Id2] - FROM [CompositeThrees] AS [c1] -) AS [t0] ON ([t].[Id1] = [t0].[OneToMany_Required_Inverse3Id1]) AND ([t].[Id2] = [t0].[OneToMany_Required_Inverse3Id2]) -ORDER BY [c].[Id2], [c].[Id1], [t].[Id2], [t].[Id1], [t0].[Id2] DESC"); + @"SELECT [c0].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2] +FROM [CompositeOnes] AS [c] +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Optional_Inverse2Id2]) +ORDER BY [c].[Id2], [c].[Id1], [c0].[Id2], [c0].[Id1]", + // + @"SELECT [c1].[Id1], [c1].[Id2], [c1].[Level2_Optional_Id1], [c1].[Level2_Optional_Id2], [c1].[Level2_Required_Id1], [c1].[Level2_Required_Id2], [c1].[Name], [c1].[OneToMany_Optional_Inverse3Id1], [c1].[OneToMany_Optional_Inverse3Id2], [c1].[OneToMany_Optional_Self_Inverse3Id1], [c1].[OneToMany_Optional_Self_Inverse3Id2], [c1].[OneToMany_Required_Inverse3Id1], [c1].[OneToMany_Required_Inverse3Id2], [c1].[OneToMany_Required_Self_Inverse3Id1], [c1].[OneToMany_Required_Self_Inverse3Id2], [c1].[OneToOne_Optional_PK_Inverse3Id1], [c1].[OneToOne_Optional_PK_Inverse3Id2], [c1].[OneToOne_Optional_Self3Id1], [c1].[OneToOne_Optional_Self3Id2], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2] +FROM [CompositeOnes] AS [c] +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Optional_Inverse2Id2]) +INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Required_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Required_Inverse3Id2]) +ORDER BY [c].[Id2], [c].[Id1], [c0].[Id2], [c0].[Id1], [c1].[Id2] DESC"); } public override async Task Projecting_multiple_collections_on_multiple_levels_no_explicit_ordering(bool async) @@ -150,14 +141,11 @@ FROM [CompositeOnes] AS [c] INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Optional_Inverse2Id2]) ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2]", // - @"SELECT [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [t].[Id1], [t].[Id2] + @"SELECT [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2] FROM [CompositeOnes] AS [c] INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Optional_Inverse2Id2]) -INNER JOIN ( - SELECT [c1].[Id1], [c1].[Id2], [c1].[OneToMany_Required_Inverse3Id1], [c1].[OneToMany_Required_Inverse3Id2] - FROM [CompositeThrees] AS [c1] -) AS [t] ON ([c0].[Id1] = [t].[OneToMany_Required_Inverse3Id1]) AND ([c0].[Id2] = [t].[OneToMany_Required_Inverse3Id2]) -ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [t].[Id2] DESC, [t].[Id1] DESC", +INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Required_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Required_Inverse3Id2]) +ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id2] DESC, [c1].[Id1] DESC", // @"SELECT [c1].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2] FROM [CompositeOnes] AS [c] @@ -179,74 +167,50 @@ INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Optional_I INNER JOIN [CompositeFours] AS [c2] ON ([c1].[Id1] = [c2].[OneToMany_Optional_Inverse4Id1]) AND ([c1].[Id2] = [c2].[OneToMany_Optional_Inverse4Id2]) ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2]", // - @"SELECT [t].[Name], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2] + @"SELECT [c0].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Name], [c0].[Id1], [c0].[Id2], CAST(LEN([c0].[Name]) AS int) AS [c], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [t].[c], [t].[Id1], [t].[Id2]", +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +ORDER BY [c].[Name], [c].[Id1], [c].[Id2], CAST(LEN([c0].[Name]) AS int), [c0].[Id1], [c0].[Id2]", // - @"SELECT [c1].[Name], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2] + @"SELECT [c1].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], CAST(LEN([c0].[Name]) AS int) AS [c], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -INNER JOIN [CompositeThrees] AS [c1] ON ([t].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([t].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) -ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [t].[c], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2]", +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) +ORDER BY [c].[Name], [c].[Id1], [c].[Id2], CAST(LEN([c0].[Name]) AS int), [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2]", // - @"SELECT [c2].[Id1], [c2].[Id2], [c2].[Level3_Optional_Id1], [c2].[Level3_Optional_Id2], [c2].[Level3_Required_Id1], [c2].[Level3_Required_Id2], [c2].[Name], [c2].[OneToMany_Optional_Inverse4Id1], [c2].[OneToMany_Optional_Inverse4Id2], [c2].[OneToMany_Optional_Self_Inverse4Id1], [c2].[OneToMany_Optional_Self_Inverse4Id2], [c2].[OneToMany_Required_Inverse4Id1], [c2].[OneToMany_Required_Inverse4Id2], [c2].[OneToMany_Required_Self_Inverse4Id1], [c2].[OneToMany_Required_Self_Inverse4Id2], [c2].[OneToOne_Optional_PK_Inverse4Id1], [c2].[OneToOne_Optional_PK_Inverse4Id2], [c2].[OneToOne_Optional_Self4Id1], [c2].[OneToOne_Optional_Self4Id2], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2] + @"SELECT [c2].[Id1], [c2].[Id2], [c2].[Level3_Optional_Id1], [c2].[Level3_Optional_Id2], [c2].[Level3_Required_Id1], [c2].[Level3_Required_Id2], [c2].[Name], [c2].[OneToMany_Optional_Inverse4Id1], [c2].[OneToMany_Optional_Inverse4Id2], [c2].[OneToMany_Optional_Self_Inverse4Id1], [c2].[OneToMany_Optional_Self_Inverse4Id2], [c2].[OneToMany_Required_Inverse4Id1], [c2].[OneToMany_Required_Inverse4Id2], [c2].[OneToMany_Required_Self_Inverse4Id1], [c2].[OneToMany_Required_Self_Inverse4Id2], [c2].[OneToOne_Optional_PK_Inverse4Id1], [c2].[OneToOne_Optional_PK_Inverse4Id2], [c2].[OneToOne_Optional_Self4Id1], [c2].[OneToOne_Optional_Self4Id2], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], CAST(LEN([c0].[Name]) AS int) AS [c], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -INNER JOIN [CompositeThrees] AS [c1] ON ([t].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([t].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) INNER JOIN [CompositeFours] AS [c2] ON ([c1].[Id1] = [c2].[OneToMany_Required_Inverse4Id1]) AND ([c1].[Id2] = [c2].[OneToMany_Required_Inverse4Id2]) -ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [t].[c], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2]", +ORDER BY [c].[Name], [c].[Id1], [c].[Id2], CAST(LEN([c0].[Name]) AS int), [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2]", // - @"SELECT [c2].[Id1], [c2].[Id2], [c2].[Level3_Optional_Id1], [c2].[Level3_Optional_Id2], [c2].[Level3_Required_Id1], [c2].[Level3_Required_Id2], [c2].[Name], [c2].[OneToMany_Optional_Inverse4Id1], [c2].[OneToMany_Optional_Inverse4Id2], [c2].[OneToMany_Optional_Self_Inverse4Id1], [c2].[OneToMany_Optional_Self_Inverse4Id2], [c2].[OneToMany_Required_Inverse4Id1], [c2].[OneToMany_Required_Inverse4Id2], [c2].[OneToMany_Required_Self_Inverse4Id1], [c2].[OneToMany_Required_Self_Inverse4Id2], [c2].[OneToOne_Optional_PK_Inverse4Id1], [c2].[OneToOne_Optional_PK_Inverse4Id2], [c2].[OneToOne_Optional_Self4Id1], [c2].[OneToOne_Optional_Self4Id2], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2] + @"SELECT [c2].[Id1], [c2].[Id2], [c2].[Level3_Optional_Id1], [c2].[Level3_Optional_Id2], [c2].[Level3_Required_Id1], [c2].[Level3_Required_Id2], [c2].[Name], [c2].[OneToMany_Optional_Inverse4Id1], [c2].[OneToMany_Optional_Inverse4Id2], [c2].[OneToMany_Optional_Self_Inverse4Id1], [c2].[OneToMany_Optional_Self_Inverse4Id2], [c2].[OneToMany_Required_Inverse4Id1], [c2].[OneToMany_Required_Inverse4Id2], [c2].[OneToMany_Required_Self_Inverse4Id1], [c2].[OneToMany_Required_Self_Inverse4Id2], [c2].[OneToOne_Optional_PK_Inverse4Id1], [c2].[OneToOne_Optional_PK_Inverse4Id2], [c2].[OneToOne_Optional_Self4Id1], [c2].[OneToOne_Optional_Self4Id2], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], CAST(LEN([c0].[Name]) AS int) AS [c], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -INNER JOIN [CompositeThrees] AS [c1] ON ([t].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([t].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) INNER JOIN [CompositeFours] AS [c2] ON ([c1].[Id1] = [c2].[OneToMany_Optional_Inverse4Id1]) AND ([c1].[Id2] = [c2].[OneToMany_Optional_Inverse4Id2]) -ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [t].[c], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2]", +ORDER BY [c].[Name], [c].[Id1], [c].[Id2], CAST(LEN([c0].[Name]) AS int), [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2]", // - @"SELECT [c1].[Name], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2] + @"SELECT [c1].[Name], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], CAST(LEN([c0].[Name]) AS int) AS [c], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -INNER JOIN [CompositeThrees] AS [c1] ON ([t].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([t].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) -ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [t].[c], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2]", +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) +ORDER BY [c].[Name], [c].[Id1], [c].[Id2], CAST(LEN([c0].[Name]) AS int), [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2]", // - @"SELECT [c2].[Id1], [c2].[Id2], [c2].[Level3_Optional_Id1], [c2].[Level3_Optional_Id2], [c2].[Level3_Required_Id1], [c2].[Level3_Required_Id2], [c2].[Name], [c2].[OneToMany_Optional_Inverse4Id1], [c2].[OneToMany_Optional_Inverse4Id2], [c2].[OneToMany_Optional_Self_Inverse4Id1], [c2].[OneToMany_Optional_Self_Inverse4Id2], [c2].[OneToMany_Required_Inverse4Id1], [c2].[OneToMany_Required_Inverse4Id2], [c2].[OneToMany_Required_Self_Inverse4Id1], [c2].[OneToMany_Required_Self_Inverse4Id2], [c2].[OneToOne_Optional_PK_Inverse4Id1], [c2].[OneToOne_Optional_PK_Inverse4Id2], [c2].[OneToOne_Optional_Self4Id1], [c2].[OneToOne_Optional_Self4Id2], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2] + @"SELECT [c2].[Id1], [c2].[Id2], [c2].[Level3_Optional_Id1], [c2].[Level3_Optional_Id2], [c2].[Level3_Required_Id1], [c2].[Level3_Required_Id2], [c2].[Name], [c2].[OneToMany_Optional_Inverse4Id1], [c2].[OneToMany_Optional_Inverse4Id2], [c2].[OneToMany_Optional_Self_Inverse4Id1], [c2].[OneToMany_Optional_Self_Inverse4Id2], [c2].[OneToMany_Required_Inverse4Id1], [c2].[OneToMany_Required_Inverse4Id2], [c2].[OneToMany_Required_Self_Inverse4Id1], [c2].[OneToMany_Required_Self_Inverse4Id2], [c2].[OneToOne_Optional_PK_Inverse4Id1], [c2].[OneToOne_Optional_PK_Inverse4Id2], [c2].[OneToOne_Optional_Self4Id1], [c2].[OneToOne_Optional_Self4Id2], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], CAST(LEN([c0].[Name]) AS int) AS [c], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -INNER JOIN [CompositeThrees] AS [c1] ON ([t].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([t].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) INNER JOIN [CompositeFours] AS [c2] ON ([c1].[Id1] = [c2].[OneToMany_Optional_Inverse4Id1]) AND ([c1].[Id2] = [c2].[OneToMany_Optional_Inverse4Id2]) -ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [t].[c], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2]", - // - @"SELECT [t0].[Id1], [t0].[Id2], [t0].[Level3_Optional_Id1], [t0].[Level3_Optional_Id2], [t0].[Level3_Required_Id1], [t0].[Level3_Required_Id2], [t0].[Name], [t0].[OneToMany_Optional_Inverse4Id1], [t0].[OneToMany_Optional_Inverse4Id2], [t0].[OneToMany_Optional_Self_Inverse4Id1], [t0].[OneToMany_Optional_Self_Inverse4Id2], [t0].[OneToMany_Required_Inverse4Id1], [t0].[OneToMany_Required_Inverse4Id2], [t0].[OneToMany_Required_Self_Inverse4Id1], [t0].[OneToMany_Required_Self_Inverse4Id2], [t0].[OneToOne_Optional_PK_Inverse4Id1], [t0].[OneToOne_Optional_PK_Inverse4Id2], [t0].[OneToOne_Optional_Self4Id1], [t0].[OneToOne_Optional_Self4Id2], [c].[Id1], [c].[Id2], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2] -FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], CAST(LEN([c0].[Name]) AS int) AS [c], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -INNER JOIN [CompositeThrees] AS [c1] ON ([t].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([t].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) -INNER JOIN ( - SELECT [c2].[Id1], [c2].[Id2], [c2].[Level3_Optional_Id1], [c2].[Level3_Optional_Id2], [c2].[Level3_Required_Id1], [c2].[Level3_Required_Id2], [c2].[Name], [c2].[OneToMany_Optional_Inverse4Id1], [c2].[OneToMany_Optional_Inverse4Id2], [c2].[OneToMany_Optional_Self_Inverse4Id1], [c2].[OneToMany_Optional_Self_Inverse4Id2], [c2].[OneToMany_Required_Inverse4Id1], [c2].[OneToMany_Required_Inverse4Id2], [c2].[OneToMany_Required_Self_Inverse4Id1], [c2].[OneToMany_Required_Self_Inverse4Id2], [c2].[OneToOne_Optional_PK_Inverse4Id1], [c2].[OneToOne_Optional_PK_Inverse4Id2], [c2].[OneToOne_Optional_Self4Id1], [c2].[OneToOne_Optional_Self4Id2], [c2].[Id1] + CAST([c2].[Id2] AS nvarchar(450)) AS [c] - FROM [CompositeFours] AS [c2] -) AS [t0] ON ([c1].[Id1] = [t0].[OneToMany_Required_Inverse4Id1]) AND ([c1].[Id2] = [t0].[OneToMany_Required_Inverse4Id2]) -ORDER BY [c].[Name], [c].[Id1], [c].[Id2], [t].[c], [t].[Id1], [t].[Id2], [c1].[Id1], [c1].[Id2], [t0].[c] DESC"); +ORDER BY [c].[Name], [c].[Id1], [c].[Id2], CAST(LEN([c0].[Name]) AS int), [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2]", + // + @"SELECT [c2].[Id1], [c2].[Id2], [c2].[Level3_Optional_Id1], [c2].[Level3_Optional_Id2], [c2].[Level3_Required_Id1], [c2].[Level3_Required_Id2], [c2].[Name], [c2].[OneToMany_Optional_Inverse4Id1], [c2].[OneToMany_Optional_Inverse4Id2], [c2].[OneToMany_Optional_Self_Inverse4Id1], [c2].[OneToMany_Optional_Self_Inverse4Id2], [c2].[OneToMany_Required_Inverse4Id1], [c2].[OneToMany_Required_Inverse4Id2], [c2].[OneToMany_Required_Self_Inverse4Id1], [c2].[OneToMany_Required_Self_Inverse4Id2], [c2].[OneToOne_Optional_PK_Inverse4Id1], [c2].[OneToOne_Optional_PK_Inverse4Id2], [c2].[OneToOne_Optional_Self4Id1], [c2].[OneToOne_Optional_Self4Id2], [c].[Id1], [c].[Id2], [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2] +FROM [CompositeOnes] AS [c] +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +INNER JOIN [CompositeThrees] AS [c1] ON ([c0].[Id1] = [c1].[OneToMany_Optional_Inverse3Id1]) AND ([c0].[Id2] = [c1].[OneToMany_Optional_Inverse3Id2]) +INNER JOIN [CompositeFours] AS [c2] ON ([c1].[Id1] = [c2].[OneToMany_Required_Inverse4Id1]) AND ([c1].[Id2] = [c2].[OneToMany_Required_Inverse4Id2]) +ORDER BY [c].[Name], [c].[Id1], [c].[Id2], CAST(LEN([c0].[Name]) AS int), [c0].[Id1], [c0].[Id2], [c1].[Id1], [c1].[Id2], [c2].[Id1] + CAST([c2].[Id2] AS nvarchar(450)) DESC"); } public override async Task Projecting_multiple_collections_same_level_top_level_ordering(bool async) @@ -298,21 +262,15 @@ public override async Task Projecting_multiple_collections_with_ordering_same_le FROM [CompositeOnes] AS [c] ORDER BY [c].[Id1], [c].[Id2]", // - @"SELECT [t].[Id1], [t].[Id2], [t].[Date], [t].[Level1_Optional_Id1], [t].[Level1_Optional_Id2], [t].[Level1_Required_Id1], [t].[Level1_Required_Id2], [t].[Name], [t].[OneToMany_Optional_Inverse2Id1], [t].[OneToMany_Optional_Inverse2Id2], [t].[OneToMany_Optional_Self_Inverse2Id1], [t].[OneToMany_Optional_Self_Inverse2Id2], [t].[OneToMany_Required_Inverse2Id1], [t].[OneToMany_Required_Inverse2Id2], [t].[OneToMany_Required_Self_Inverse2Id1], [t].[OneToMany_Required_Self_Inverse2Id2], [t].[OneToOne_Optional_PK_Inverse2Id1], [t].[OneToOne_Optional_PK_Inverse2Id2], [t].[OneToOne_Optional_Self2Id1], [t].[OneToOne_Optional_Self2Id2], [c].[Id1], [c].[Id2] + @"SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2], [c].[Id1], [c].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Optional_Inverse2Id2]) -ORDER BY [c].[Id1], [c].[Id2], [t].[Id2]", +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Optional_Inverse2Id2]) +ORDER BY [c].[Id1], [c].[Id2], [c0].[Id2]", // - @"SELECT [t].[Id1], [t].[Id2], [t].[Date], [t].[Level1_Optional_Id1], [t].[Level1_Optional_Id2], [t].[Level1_Required_Id1], [t].[Level1_Required_Id2], [t].[Name], [t].[OneToMany_Optional_Inverse2Id1], [t].[OneToMany_Optional_Inverse2Id2], [t].[OneToMany_Optional_Self_Inverse2Id1], [t].[OneToMany_Optional_Self_Inverse2Id2], [t].[OneToMany_Required_Inverse2Id1], [t].[OneToMany_Required_Inverse2Id2], [t].[OneToMany_Required_Self_Inverse2Id1], [t].[OneToMany_Required_Self_Inverse2Id2], [t].[OneToOne_Optional_PK_Inverse2Id1], [t].[OneToOne_Optional_PK_Inverse2Id2], [t].[OneToOne_Optional_Self2Id1], [t].[OneToOne_Optional_Self2Id2], [c].[Id1], [c].[Id2] + @"SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2], [c].[Id1], [c].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -ORDER BY [c].[Id1], [c].[Id2], [t].[Name] DESC"); +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +ORDER BY [c].[Id1], [c].[Id2], [c0].[Name] DESC"); } public override async Task Projecting_multiple_collections_with_ordering_same_level_top_level_ordering(bool async) @@ -324,21 +282,15 @@ public override async Task Projecting_multiple_collections_with_ordering_same_le FROM [CompositeOnes] AS [c] ORDER BY [c].[Id2], [c].[Id1]", // - @"SELECT [t].[Id1], [t].[Id2], [t].[Date], [t].[Level1_Optional_Id1], [t].[Level1_Optional_Id2], [t].[Level1_Required_Id1], [t].[Level1_Required_Id2], [t].[Name], [t].[OneToMany_Optional_Inverse2Id1], [t].[OneToMany_Optional_Inverse2Id2], [t].[OneToMany_Optional_Self_Inverse2Id1], [t].[OneToMany_Optional_Self_Inverse2Id2], [t].[OneToMany_Required_Inverse2Id1], [t].[OneToMany_Required_Inverse2Id2], [t].[OneToMany_Required_Self_Inverse2Id1], [t].[OneToMany_Required_Self_Inverse2Id2], [t].[OneToOne_Optional_PK_Inverse2Id1], [t].[OneToOne_Optional_PK_Inverse2Id2], [t].[OneToOne_Optional_Self2Id1], [t].[OneToOne_Optional_Self2Id2], [c].[Id1], [c].[Id2] + @"SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2], [c].[Id1], [c].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Optional_Inverse2Id2]) -ORDER BY [c].[Id2], [c].[Id1], [t].[Id2]", +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Optional_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Optional_Inverse2Id2]) +ORDER BY [c].[Id2], [c].[Id1], [c0].[Id2]", // - @"SELECT [t].[Id1], [t].[Id2], [t].[Date], [t].[Level1_Optional_Id1], [t].[Level1_Optional_Id2], [t].[Level1_Required_Id1], [t].[Level1_Required_Id2], [t].[Name], [t].[OneToMany_Optional_Inverse2Id1], [t].[OneToMany_Optional_Inverse2Id2], [t].[OneToMany_Optional_Self_Inverse2Id1], [t].[OneToMany_Optional_Self_Inverse2Id2], [t].[OneToMany_Required_Inverse2Id1], [t].[OneToMany_Required_Inverse2Id2], [t].[OneToMany_Required_Self_Inverse2Id1], [t].[OneToMany_Required_Self_Inverse2Id2], [t].[OneToOne_Optional_PK_Inverse2Id1], [t].[OneToOne_Optional_PK_Inverse2Id2], [t].[OneToOne_Optional_Self2Id1], [t].[OneToOne_Optional_Self2Id2], [c].[Id1], [c].[Id2] + @"SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2], [c].[Id1], [c].[Id2] FROM [CompositeOnes] AS [c] -INNER JOIN ( - SELECT [c0].[Id1], [c0].[Id2], [c0].[Date], [c0].[Level1_Optional_Id1], [c0].[Level1_Optional_Id2], [c0].[Level1_Required_Id1], [c0].[Level1_Required_Id2], [c0].[Name], [c0].[OneToMany_Optional_Inverse2Id1], [c0].[OneToMany_Optional_Inverse2Id2], [c0].[OneToMany_Optional_Self_Inverse2Id1], [c0].[OneToMany_Optional_Self_Inverse2Id2], [c0].[OneToMany_Required_Inverse2Id1], [c0].[OneToMany_Required_Inverse2Id2], [c0].[OneToMany_Required_Self_Inverse2Id1], [c0].[OneToMany_Required_Self_Inverse2Id2], [c0].[OneToOne_Optional_PK_Inverse2Id1], [c0].[OneToOne_Optional_PK_Inverse2Id2], [c0].[OneToOne_Optional_Self2Id1], [c0].[OneToOne_Optional_Self2Id2] - FROM [CompositeTwos] AS [c0] -) AS [t] ON ([c].[Id1] = [t].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [t].[OneToMany_Required_Inverse2Id2]) -ORDER BY [c].[Id2], [c].[Id1], [t].[Name] DESC"); +INNER JOIN [CompositeTwos] AS [c0] ON ([c].[Id1] = [c0].[OneToMany_Required_Inverse2Id1]) AND ([c].[Id2] = [c0].[OneToMany_Required_Inverse2Id2]) +ORDER BY [c].[Id2], [c].[Id1], [c0].[Name] DESC"); } private void AssertSql(params string[] expected) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index 49c0c3fcee8..7bc0b549a99 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -1753,12 +1753,9 @@ public override async Task Join_with_order_by_without_skip_or_take(bool async) await base.Join_with_order_by_without_skip_or_take(async); AssertSql( - @"SELECT [t].[Name], [g].[FullName] + @"SELECT [w].[Name], [g].[FullName] FROM [Gears] AS [g] -INNER JOIN ( - SELECT [w].[Name], [w].[OwnerFullName] - FROM [Weapons] AS [w] -) AS [t] ON [g].[FullName] = [t].[OwnerFullName]"); +INNER JOIN [Weapons] AS [w] ON [g].[FullName] = [w].[OwnerFullName]"); } public override async Task Join_with_order_by_without_skip_or_take_nested(bool async) @@ -1766,16 +1763,10 @@ public override async Task Join_with_order_by_without_skip_or_take_nested(bool a await base.Join_with_order_by_without_skip_or_take_nested(async); AssertSql( - @"SELECT [t0].[Name], [t].[FullName] + @"SELECT [w].[Name], [g].[FullName] FROM [Squads] AS [s] -INNER JOIN ( - SELECT [g].[SquadId], [g].[FullName] - FROM [Gears] AS [g] -) AS [t] ON [s].[Id] = [t].[SquadId] -INNER JOIN ( - SELECT [w].[Name], [w].[OwnerFullName] - FROM [Weapons] AS [w] -) AS [t0] ON [t].[FullName] = [t0].[OwnerFullName]"); +INNER JOIN [Gears] AS [g] ON [s].[Id] = [g].[SquadId] +INNER JOIN [Weapons] AS [w] ON [g].[FullName] = [w].[OwnerFullName]"); } public override async Task Collection_with_inheritance_and_join_include_joined(bool async) @@ -2915,13 +2906,10 @@ public override async Task Subquery_is_lifted_from_additional_from_clause(bool a await base.Subquery_is_lifted_from_additional_from_clause(async); AssertSql( - @"SELECT [g].[FullName] AS [Name1], [t].[FullName] AS [Name2] + @"SELECT [g].[FullName] AS [Name1], [g0].[FullName] AS [Name2] FROM [Gears] AS [g] -CROSS JOIN ( - SELECT [g0].[FullName], [g0].[HasSoulPatch] - FROM [Gears] AS [g0] -) AS [t] -WHERE ([g].[HasSoulPatch] = CAST(1 AS bit)) AND ([t].[HasSoulPatch] = CAST(0 AS bit)) +CROSS JOIN [Gears] AS [g0] +WHERE ([g].[HasSoulPatch] = CAST(1 AS bit)) AND ([g0].[HasSoulPatch] = CAST(0 AS bit)) ORDER BY [g].[FullName]"); } @@ -3959,19 +3947,16 @@ public override async Task Correlated_collections_different_collections_projecte await base.Correlated_collections_different_collections_projected(async); AssertSql( - @"SELECT [g].[Nickname], [g].[SquadId], [t].[Name], [t].[IsAutomatic], [t].[Id], [t0].[Nickname], [t0].[Rank], [t0].[SquadId] + @"SELECT [g].[Nickname], [g].[SquadId], [t].[Name], [t].[IsAutomatic], [t].[Id], [g0].[Nickname], [g0].[Rank], [g0].[SquadId] FROM [Gears] AS [g] LEFT JOIN ( SELECT [w].[Name], [w].[IsAutomatic], [w].[Id], [w].[OwnerFullName] FROM [Weapons] AS [w] WHERE [w].[IsAutomatic] = CAST(1 AS bit) ) AS [t] ON [g].[FullName] = [t].[OwnerFullName] -LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[Rank], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] -) AS [t0] ON ([g].[Nickname] = [t0].[LeaderNickname]) AND ([g].[SquadId] = [t0].[LeaderSquadId]) +LEFT JOIN [Gears] AS [g0] ON ([g].[Nickname] = [g0].[LeaderNickname]) AND ([g].[SquadId] = [g0].[LeaderSquadId]) WHERE [g].[Discriminator] = N'Officer' -ORDER BY [g].[FullName], [g].[Nickname], [g].[SquadId], [t].[Id], [t0].[FullName], [t0].[Nickname]"); +ORDER BY [g].[FullName], [g].[Nickname], [g].[SquadId], [t].[Id], [g0].[FullName], [g0].[Nickname]"); } public override async Task Multiple_orderby_with_navigation_expansion_on_one_of_the_order_bys(bool async) @@ -4062,37 +4047,34 @@ public override async Task Correlated_collections_multiple_nested_complex_collec await base.Correlated_collections_multiple_nested_complex_collections(async); AssertSql( - @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t].[Id], [g1].[Nickname], [g1].[SquadId], [t1].[FullName], [t1].[Nickname], [t1].[SquadId], [t1].[Id], [t1].[Nickname0], [t1].[SquadId0], [t1].[Id0], [t1].[Name], [t1].[IsAutomatic], [t1].[Id1], [t1].[Nickname00], [t1].[HasSoulPatch], [t1].[SquadId00], [t3].[Id], [t3].[AmmunitionType], [t3].[IsAutomatic], [t3].[Name], [t3].[OwnerFullName], [t3].[SynergyWithId], [t3].[Nickname], [t3].[SquadId] + @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t].[Id], [g1].[Nickname], [g1].[SquadId], [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t0].[Id], [t0].[Nickname0], [t0].[SquadId0], [t0].[Id0], [t0].[Name], [t0].[IsAutomatic], [t0].[Id1], [t0].[Nickname00], [t0].[HasSoulPatch], [t0].[SquadId00], [t2].[Id], [t2].[AmmunitionType], [t2].[IsAutomatic], [t2].[Name], [t2].[OwnerFullName], [t2].[SynergyWithId], [t2].[Nickname], [t2].[SquadId] FROM [Gears] AS [g] LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId]) LEFT JOIN [Gears] AS [g1] ON ([t].[GearNickName] = [g1].[Nickname]) AND ([t].[GearSquadId] = [g1].[SquadId]) LEFT JOIN ( - SELECT [g2].[FullName], [g2].[Nickname], [g2].[SquadId], [t0].[Id], [t0].[Nickname] AS [Nickname0], [t0].[SquadId] AS [SquadId0], [t0].[Id0], [t0].[Name], [t0].[IsAutomatic], [t0].[Id1], [t0].[Nickname0] AS [Nickname00], [t0].[HasSoulPatch], [t0].[SquadId0] AS [SquadId00], [g2].[Rank], [t0].[IsAutomatic0], [g2].[LeaderNickname], [g2].[LeaderSquadId] + SELECT [g2].[FullName], [g2].[Nickname], [g2].[SquadId], [t1].[Id], [t1].[Nickname] AS [Nickname0], [t1].[SquadId] AS [SquadId0], [t1].[Id0], [t1].[Name], [t1].[IsAutomatic], [t1].[Id1], [t1].[Nickname0] AS [Nickname00], [t1].[HasSoulPatch], [t1].[SquadId0] AS [SquadId00], [g2].[Rank], [t1].[IsAutomatic0], [g2].[LeaderNickname], [g2].[LeaderSquadId] FROM [Gears] AS [g2] LEFT JOIN ( - SELECT [w].[Id], [g3].[Nickname], [g3].[SquadId], [s].[Id] AS [Id0], [w0].[Name], [w0].[IsAutomatic], [w0].[Id] AS [Id1], [t2].[Nickname] AS [Nickname0], [t2].[HasSoulPatch], [t2].[SquadId] AS [SquadId0], [w].[IsAutomatic] AS [IsAutomatic0], [w].[OwnerFullName] + SELECT [w].[Id], [g3].[Nickname], [g3].[SquadId], [s].[Id] AS [Id0], [w0].[Name], [w0].[IsAutomatic], [w0].[Id] AS [Id1], [g4].[Nickname] AS [Nickname0], [g4].[HasSoulPatch], [g4].[SquadId] AS [SquadId0], [w].[IsAutomatic] AS [IsAutomatic0], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN [Gears] AS [g3] ON [w].[OwnerFullName] = [g3].[FullName] LEFT JOIN [Squads] AS [s] ON [g3].[SquadId] = [s].[Id] LEFT JOIN [Weapons] AS [w0] ON [g3].[FullName] = [w0].[OwnerFullName] - LEFT JOIN ( - SELECT [g4].[Nickname], [g4].[HasSoulPatch], [g4].[SquadId] - FROM [Gears] AS [g4] - ) AS [t2] ON [s].[Id] = [t2].[SquadId] + LEFT JOIN [Gears] AS [g4] ON [s].[Id] = [g4].[SquadId] WHERE ([w].[Name] <> N'Bar') OR [w].[Name] IS NULL - ) AS [t0] ON [g2].[FullName] = [t0].[OwnerFullName] + ) AS [t1] ON [g2].[FullName] = [t1].[OwnerFullName] WHERE [g2].[FullName] <> N'Foo' -) AS [t1] ON ([g].[Nickname] = [t1].[LeaderNickname]) AND ([g].[SquadId] = [t1].[LeaderSquadId]) +) AS [t0] ON ([g].[Nickname] = [t0].[LeaderNickname]) AND ([g].[SquadId] = [t0].[LeaderSquadId]) LEFT JOIN ( SELECT [w1].[Id], [w1].[AmmunitionType], [w1].[IsAutomatic], [w1].[Name], [w1].[OwnerFullName], [w1].[SynergyWithId], [g5].[Nickname], [g5].[SquadId] FROM [Weapons] AS [w1] LEFT JOIN [Gears] AS [g5] ON [w1].[OwnerFullName] = [g5].[FullName] -) AS [t3] ON [g1].[FullName] = [t3].[OwnerFullName] +) AS [t2] ON [g1].[FullName] = [t2].[OwnerFullName] WHERE ([g].[Discriminator] = N'Officer') AND EXISTS ( SELECT 1 FROM [Gears] AS [g0] WHERE ([g].[Nickname] = [g0].[LeaderNickname]) AND ([g].[SquadId] = [g0].[LeaderSquadId])) -ORDER BY [g].[HasSoulPatch] DESC, [t].[Note], [g].[Nickname], [g].[SquadId], [t].[Id], [g1].[Nickname], [g1].[SquadId], [t1].[Rank], [t1].[Nickname], [t1].[SquadId], [t1].[IsAutomatic0], [t1].[Id], [t1].[Nickname0], [t1].[SquadId0], [t1].[Id0], [t1].[Id1], [t1].[Nickname00], [t1].[SquadId00], [t3].[IsAutomatic], [t3].[Nickname] DESC, [t3].[Id]"); +ORDER BY [g].[HasSoulPatch] DESC, [t].[Note], [g].[Nickname], [g].[SquadId], [t].[Id], [g1].[Nickname], [g1].[SquadId], [t0].[Rank], [t0].[Nickname], [t0].[SquadId], [t0].[IsAutomatic0], [t0].[Id], [t0].[Nickname0], [t0].[SquadId0], [t0].[Id0], [t0].[Id1], [t0].[Nickname00], [t0].[SquadId00], [t2].[IsAutomatic], [t2].[Nickname] DESC, [t2].[Id]"); } public override async Task Correlated_collections_inner_subquery_selector_references_outer_qsre(bool async) @@ -4364,19 +4346,16 @@ public override async Task Correlated_collections_complex_scenario1(bool async) await base.Correlated_collections_complex_scenario1(async); AssertSql( - @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t0].[Id], [t0].[Nickname], [t0].[SquadId], [t0].[Id0], [t0].[Nickname0], [t0].[HasSoulPatch], [t0].[SquadId0] + @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t].[Id], [t].[Nickname], [t].[SquadId], [t].[Id0], [t].[Nickname0], [t].[HasSoulPatch], [t].[SquadId0] FROM [Gears] AS [g] LEFT JOIN ( - SELECT [w].[Id], [g0].[Nickname], [g0].[SquadId], [s].[Id] AS [Id0], [t].[Nickname] AS [Nickname0], [t].[HasSoulPatch], [t].[SquadId] AS [SquadId0], [w].[OwnerFullName] + SELECT [w].[Id], [g0].[Nickname], [g0].[SquadId], [s].[Id] AS [Id0], [g1].[Nickname] AS [Nickname0], [g1].[HasSoulPatch], [g1].[SquadId] AS [SquadId0], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN [Gears] AS [g0] ON [w].[OwnerFullName] = [g0].[FullName] LEFT JOIN [Squads] AS [s] ON [g0].[SquadId] = [s].[Id] - LEFT JOIN ( - SELECT [g1].[Nickname], [g1].[HasSoulPatch], [g1].[SquadId] - FROM [Gears] AS [g1] - ) AS [t] ON [s].[Id] = [t].[SquadId] -) AS [t0] ON [g].[FullName] = [t0].[OwnerFullName] -ORDER BY [g].[Nickname], [g].[SquadId], [t0].[Id], [t0].[Nickname], [t0].[SquadId], [t0].[Id0], [t0].[Nickname0]"); + LEFT JOIN [Gears] AS [g1] ON [s].[Id] = [g1].[SquadId] +) AS [t] ON [g].[FullName] = [t].[OwnerFullName] +ORDER BY [g].[Nickname], [g].[SquadId], [t].[Id], [t].[Nickname], [t].[SquadId], [t].[Id0], [t].[Nickname0]"); } public override async Task Correlated_collections_complex_scenario2(bool async) @@ -4384,24 +4363,21 @@ public override async Task Correlated_collections_complex_scenario2(bool async) await base.Correlated_collections_complex_scenario2(async); AssertSql( - @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t1].[FullName], [t1].[Nickname], [t1].[SquadId], [t1].[Id], [t1].[Nickname0], [t1].[SquadId0], [t1].[Id0], [t1].[Nickname00], [t1].[HasSoulPatch], [t1].[SquadId00] + @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t0].[Id], [t0].[Nickname0], [t0].[SquadId0], [t0].[Id0], [t0].[Nickname00], [t0].[HasSoulPatch], [t0].[SquadId00] FROM [Gears] AS [g] LEFT JOIN ( - SELECT [g0].[FullName], [g0].[Nickname], [g0].[SquadId], [t0].[Id], [t0].[Nickname] AS [Nickname0], [t0].[SquadId] AS [SquadId0], [t0].[Id0], [t0].[Nickname0] AS [Nickname00], [t0].[HasSoulPatch], [t0].[SquadId0] AS [SquadId00], [g0].[LeaderNickname], [g0].[LeaderSquadId] + SELECT [g0].[FullName], [g0].[Nickname], [g0].[SquadId], [t].[Id], [t].[Nickname] AS [Nickname0], [t].[SquadId] AS [SquadId0], [t].[Id0], [t].[Nickname0] AS [Nickname00], [t].[HasSoulPatch], [t].[SquadId0] AS [SquadId00], [g0].[LeaderNickname], [g0].[LeaderSquadId] FROM [Gears] AS [g0] LEFT JOIN ( - SELECT [w].[Id], [g1].[Nickname], [g1].[SquadId], [s].[Id] AS [Id0], [t].[Nickname] AS [Nickname0], [t].[HasSoulPatch], [t].[SquadId] AS [SquadId0], [w].[OwnerFullName] + SELECT [w].[Id], [g1].[Nickname], [g1].[SquadId], [s].[Id] AS [Id0], [g2].[Nickname] AS [Nickname0], [g2].[HasSoulPatch], [g2].[SquadId] AS [SquadId0], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN [Gears] AS [g1] ON [w].[OwnerFullName] = [g1].[FullName] LEFT JOIN [Squads] AS [s] ON [g1].[SquadId] = [s].[Id] - LEFT JOIN ( - SELECT [g2].[Nickname], [g2].[HasSoulPatch], [g2].[SquadId] - FROM [Gears] AS [g2] - ) AS [t] ON [s].[Id] = [t].[SquadId] - ) AS [t0] ON [g0].[FullName] = [t0].[OwnerFullName] -) AS [t1] ON ([g].[Nickname] = [t1].[LeaderNickname]) AND ([g].[SquadId] = [t1].[LeaderSquadId]) + LEFT JOIN [Gears] AS [g2] ON [s].[Id] = [g2].[SquadId] + ) AS [t] ON [g0].[FullName] = [t].[OwnerFullName] +) AS [t0] ON ([g].[Nickname] = [t0].[LeaderNickname]) AND ([g].[SquadId] = [t0].[LeaderSquadId]) WHERE [g].[Discriminator] = N'Officer' -ORDER BY [g].[Nickname], [g].[SquadId], [t1].[Nickname], [t1].[SquadId], [t1].[Id], [t1].[Nickname0], [t1].[SquadId0], [t1].[Id0], [t1].[Nickname00]"); +ORDER BY [g].[Nickname], [g].[SquadId], [t0].[Nickname], [t0].[SquadId], [t0].[Id], [t0].[Nickname0], [t0].[SquadId0], [t0].[Id0], [t0].[Nickname00]"); } public override async Task Correlated_collections_with_funky_orderby_complex_scenario1(bool async) @@ -4409,19 +4385,16 @@ public override async Task Correlated_collections_with_funky_orderby_complex_sce await base.Correlated_collections_with_funky_orderby_complex_scenario1(async); AssertSql( - @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t0].[Id], [t0].[Nickname], [t0].[SquadId], [t0].[Id0], [t0].[Nickname0], [t0].[HasSoulPatch], [t0].[SquadId0] + @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t].[Id], [t].[Nickname], [t].[SquadId], [t].[Id0], [t].[Nickname0], [t].[HasSoulPatch], [t].[SquadId0] FROM [Gears] AS [g] LEFT JOIN ( - SELECT [w].[Id], [g0].[Nickname], [g0].[SquadId], [s].[Id] AS [Id0], [t].[Nickname] AS [Nickname0], [t].[HasSoulPatch], [t].[SquadId] AS [SquadId0], [w].[OwnerFullName] + SELECT [w].[Id], [g0].[Nickname], [g0].[SquadId], [s].[Id] AS [Id0], [g1].[Nickname] AS [Nickname0], [g1].[HasSoulPatch], [g1].[SquadId] AS [SquadId0], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN [Gears] AS [g0] ON [w].[OwnerFullName] = [g0].[FullName] LEFT JOIN [Squads] AS [s] ON [g0].[SquadId] = [s].[Id] - LEFT JOIN ( - SELECT [g1].[Nickname], [g1].[HasSoulPatch], [g1].[SquadId] - FROM [Gears] AS [g1] - ) AS [t] ON [s].[Id] = [t].[SquadId] -) AS [t0] ON [g].[FullName] = [t0].[OwnerFullName] -ORDER BY [g].[FullName], [g].[Nickname] DESC, [g].[SquadId], [t0].[Id], [t0].[Nickname], [t0].[SquadId], [t0].[Id0], [t0].[Nickname0]"); + LEFT JOIN [Gears] AS [g1] ON [s].[Id] = [g1].[SquadId] +) AS [t] ON [g].[FullName] = [t].[OwnerFullName] +ORDER BY [g].[FullName], [g].[Nickname] DESC, [g].[SquadId], [t].[Id], [t].[Nickname], [t].[SquadId], [t].[Id0], [t].[Nickname0]"); } public override async Task Correlated_collections_with_funky_orderby_complex_scenario2(bool async) @@ -4429,24 +4402,21 @@ public override async Task Correlated_collections_with_funky_orderby_complex_sce await base.Correlated_collections_with_funky_orderby_complex_scenario2(async); AssertSql( - @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t1].[FullName], [t1].[Nickname], [t1].[SquadId], [t1].[Id], [t1].[Nickname0], [t1].[SquadId0], [t1].[Id0], [t1].[Nickname00], [t1].[HasSoulPatch], [t1].[SquadId00] + @"SELECT [g].[FullName], [g].[Nickname], [g].[SquadId], [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t0].[Id], [t0].[Nickname0], [t0].[SquadId0], [t0].[Id0], [t0].[Nickname00], [t0].[HasSoulPatch], [t0].[SquadId00] FROM [Gears] AS [g] LEFT JOIN ( - SELECT [g0].[FullName], [g0].[Nickname], [g0].[SquadId], [t0].[Id], [t0].[Nickname] AS [Nickname0], [t0].[SquadId] AS [SquadId0], [t0].[Id0], [t0].[Nickname0] AS [Nickname00], [t0].[HasSoulPatch], [t0].[SquadId0] AS [SquadId00], [g0].[HasSoulPatch] AS [HasSoulPatch0], [t0].[IsAutomatic], [t0].[Name], [g0].[LeaderNickname], [g0].[LeaderSquadId] + SELECT [g0].[FullName], [g0].[Nickname], [g0].[SquadId], [t].[Id], [t].[Nickname] AS [Nickname0], [t].[SquadId] AS [SquadId0], [t].[Id0], [t].[Nickname0] AS [Nickname00], [t].[HasSoulPatch], [t].[SquadId0] AS [SquadId00], [g0].[HasSoulPatch] AS [HasSoulPatch0], [t].[IsAutomatic], [t].[Name], [g0].[LeaderNickname], [g0].[LeaderSquadId] FROM [Gears] AS [g0] LEFT JOIN ( - SELECT [w].[Id], [g1].[Nickname], [g1].[SquadId], [s].[Id] AS [Id0], [t].[Nickname] AS [Nickname0], [t].[HasSoulPatch], [t].[SquadId] AS [SquadId0], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName] + SELECT [w].[Id], [g1].[Nickname], [g1].[SquadId], [s].[Id] AS [Id0], [g2].[Nickname] AS [Nickname0], [g2].[HasSoulPatch], [g2].[SquadId] AS [SquadId0], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN [Gears] AS [g1] ON [w].[OwnerFullName] = [g1].[FullName] LEFT JOIN [Squads] AS [s] ON [g1].[SquadId] = [s].[Id] - LEFT JOIN ( - SELECT [g2].[Nickname], [g2].[HasSoulPatch], [g2].[SquadId] - FROM [Gears] AS [g2] - ) AS [t] ON [s].[Id] = [t].[SquadId] - ) AS [t0] ON [g0].[FullName] = [t0].[OwnerFullName] -) AS [t1] ON ([g].[Nickname] = [t1].[LeaderNickname]) AND ([g].[SquadId] = [t1].[LeaderSquadId]) + LEFT JOIN [Gears] AS [g2] ON [s].[Id] = [g2].[SquadId] + ) AS [t] ON [g0].[FullName] = [t].[OwnerFullName] +) AS [t0] ON ([g].[Nickname] = [t0].[LeaderNickname]) AND ([g].[SquadId] = [t0].[LeaderSquadId]) WHERE [g].[Discriminator] = N'Officer' -ORDER BY [g].[HasSoulPatch], [g].[LeaderNickname], [g].[FullName], [g].[Nickname], [g].[SquadId], [t1].[FullName], [t1].[HasSoulPatch0] DESC, [t1].[Nickname], [t1].[SquadId], [t1].[IsAutomatic], [t1].[Name] DESC, [t1].[Id], [t1].[Nickname0], [t1].[SquadId0], [t1].[Id0], [t1].[Nickname00]"); +ORDER BY [g].[HasSoulPatch], [g].[LeaderNickname], [g].[FullName], [g].[Nickname], [g].[SquadId], [t0].[FullName], [t0].[HasSoulPatch0] DESC, [t0].[Nickname], [t0].[SquadId], [t0].[IsAutomatic], [t0].[Name] DESC, [t0].[Id], [t0].[Nickname0], [t0].[SquadId0], [t0].[Id0], [t0].[Nickname00]"); } public override async Task Correlated_collection_with_top_level_FirstOrDefault(bool async) @@ -4493,17 +4463,14 @@ public override async Task Correlated_collection_with_top_level_Last_with_order_ await base.Correlated_collection_with_top_level_Last_with_order_by_on_inner(async); AssertSql( - @"SELECT [t].[Nickname], [t].[SquadId], [t0].[Id], [t0].[AmmunitionType], [t0].[IsAutomatic], [t0].[Name], [t0].[OwnerFullName], [t0].[SynergyWithId] + @"SELECT [t].[Nickname], [t].[SquadId], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM ( SELECT TOP(1) [g].[Nickname], [g].[SquadId], [g].[FullName] FROM [Gears] AS [g] ORDER BY [g].[FullName] DESC ) AS [t] -LEFT JOIN ( - SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] - FROM [Weapons] AS [w] -) AS [t0] ON [t].[FullName] = [t0].[OwnerFullName] -ORDER BY [t].[FullName] DESC, [t].[Nickname], [t].[SquadId], [t0].[Name]"); +LEFT JOIN [Weapons] AS [w] ON [t].[FullName] = [w].[OwnerFullName] +ORDER BY [t].[FullName] DESC, [t].[Nickname], [t].[SquadId], [w].[Name]"); } public override async Task Null_semantics_on_nullable_bool_from_inner_join_subquery_is_fully_applied(bool async) @@ -5322,14 +5289,11 @@ public override async Task Cast_ordered_subquery_to_base_type_using_typed_ToArra await base.Cast_ordered_subquery_to_base_type_using_typed_ToArray(async); AssertSql( - @"SELECT [c].[Name], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Nickname], [t].[Rank], [t].[SquadId] + @"SELECT [c].[Name], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Nickname], [g].[Rank], [g].[SquadId] FROM [Cities] AS [c] -LEFT JOIN ( - SELECT [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Nickname], [g].[Rank], [g].[SquadId], [g].[AssignedCityName] - FROM [Gears] AS [g] -) AS [t] ON [c].[Name] = [t].[AssignedCityName] +LEFT JOIN [Gears] AS [g] ON [c].[Name] = [g].[AssignedCityName] WHERE [c].[Name] = N'Ephyra' -ORDER BY [c].[Name], [t].[Nickname] DESC"); +ORDER BY [c].[Name], [g].[Nickname] DESC"); } public override async Task Correlated_collection_with_complex_order_by_funcletized_to_constant_bool(bool async) @@ -6028,7 +5992,7 @@ FROM [Gears] AS [g0] WHERE [t1].[row] <= 50 ) AS [t0] ON (([g].[Nickname] = [t0].[LeaderNickname]) OR ([g].[Nickname] IS NULL AND [t0].[LeaderNickname] IS NULL)) AND ([g].[SquadId] = [t0].[LeaderSquadId]) WHERE [g].[Discriminator] = N'Officer' -ORDER BY [t].[Id], [g].[Nickname], [g].[SquadId], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Nickname], [t0].[SquadId]"); +ORDER BY [t].[Id], [g].[Nickname], [g].[SquadId], [t0].[Nickname]"); } public override async Task Project_collection_navigation_nested_composite_key(bool async) @@ -7400,7 +7364,7 @@ FROM [Weapons] AS [w] ) AS [t] WHERE [t].[row] <= 10 ) AS [t0] ON [g].[FullName] = [t0].[OwnerFullName] -ORDER BY [g].[Nickname], [g].[SquadId], [c].[Name], [t0].[OwnerFullName], [t0].[Id]"); +ORDER BY [g].[Nickname], [g].[SquadId], [c].[Name]"); } public override async Task FirstOrDefault_on_empty_collection_of_DateTime_in_subquery(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs index 719fe3cac8e..994125ff022 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs @@ -1969,17 +1969,14 @@ public override async Task GroupBy_select_grouping_composed_list_2(bool async) await base.GroupBy_select_grouping_composed_list_2(async); AssertSql( - @"SELECT [t].[City], [t0].[CustomerID], [t0].[Address], [t0].[City], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Country], [t0].[Fax], [t0].[Phone], [t0].[PostalCode], [t0].[Region] + @"SELECT [t].[City], [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region] FROM ( SELECT [c].[City] FROM [Customers] AS [c] GROUP BY [c].[City] ) AS [t] -LEFT JOIN ( - SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region] - FROM [Customers] AS [c0] -) AS [t0] ON [t].[City] = [t0].[City] -ORDER BY [t].[City], [t0].[CustomerID]"); +LEFT JOIN [Customers] AS [c0] ON [t].[City] = [c0].[City] +ORDER BY [t].[City], [c0].[CustomerID]"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs index f38630ac6cd..65da90cd110 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs @@ -1543,20 +1543,17 @@ public override async Task Filtered_include_with_multiple_ordering(bool async) await base.Filtered_include_with_multiple_ordering(async); AssertSql( - @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate] + @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] FROM [Customers] AS [c] OUTER APPLY ( - SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] - FROM ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] - WHERE [c].[CustomerID] = [o].[CustomerID] - ORDER BY [o].[OrderID] - OFFSET 1 ROWS - ) AS [t] -) AS [t0] + SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] + FROM [Orders] AS [o] + WHERE [c].[CustomerID] = [o].[CustomerID] + ORDER BY [o].[OrderID] + OFFSET 1 ROWS +) AS [t] WHERE [c].[CustomerID] LIKE N'F%' -ORDER BY [c].[CustomerID], [t0].[OrderDate] DESC"); +ORDER BY [c].[CustomerID], [t].[OrderDate] DESC"); } public override async Task Outer_idenfier_correctly_determined_when_doing_include_on_right_side_of_left_join(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindJoinQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindJoinQuerySqlServerTest.cs index b3c32d7c080..0253a116cca 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindJoinQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindJoinQuerySqlServerTest.cs @@ -109,13 +109,10 @@ public override async Task Join_customers_orders_with_subquery(bool async) await base.Join_customers_orders_with_subquery(async); AssertSql( - @"SELECT [c].[ContactName], [t].[OrderID] + @"SELECT [c].[ContactName], [o].[OrderID] FROM [Customers] AS [c] -INNER JOIN ( - SELECT [o].[OrderID], [o].[CustomerID] - FROM [Orders] AS [o] -) AS [t] ON [c].[CustomerID] = [t].[CustomerID] -WHERE [t].[CustomerID] = N'ALFKI'"); +INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [o].[CustomerID] = N'ALFKI'"); } public override async Task Join_customers_orders_with_subquery_with_take(bool async) @@ -140,13 +137,10 @@ public override async Task Join_customers_orders_with_subquery_anonymous_propert await base.Join_customers_orders_with_subquery_anonymous_property_method(async); AssertSql( - @"SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] + @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] -INNER JOIN ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] -) AS [t] ON [c].[CustomerID] = [t].[CustomerID] -WHERE [t].[CustomerID] = N'ALFKI'"); +INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [o].[CustomerID] = N'ALFKI'"); } public override async Task Join_customers_orders_with_subquery_anonymous_property_method_with_take(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs index 6e7d24c3546..caff165231e 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs @@ -307,7 +307,7 @@ WHERE [o].[OrderID] < 10500 WHERE [t].[row] <= 3 ) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID] WHERE [c].[CustomerID] LIKE N'A%' -ORDER BY [c].[CustomerID], [t0].[CustomerID], [t0].[OrderID]"); +ORDER BY [c].[CustomerID]"); } public override void Select_nested_collection_multi_level2() @@ -1441,12 +1441,9 @@ public override async Task Reverse_in_join_outer(bool async) await base.Reverse_in_join_outer(async); AssertSql( - @"SELECT [c].[CustomerID], [t].[OrderID] + @"SELECT [c].[CustomerID], [o].[OrderID] FROM [Customers] AS [c] -INNER JOIN ( - SELECT [o].[OrderID], [o].[CustomerID] - FROM [Orders] AS [o] -) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] ORDER BY [c].[City], [c].[CustomerID] DESC"); } @@ -1457,16 +1454,13 @@ public override async Task Reverse_in_join_outer_with_take(bool async) AssertSql( @"@__p_0='20' -SELECT [t].[CustomerID], [t0].[OrderID] +SELECT [t].[CustomerID], [o].[OrderID] FROM ( SELECT TOP(@__p_0) [c].[CustomerID] FROM [Customers] AS [c] ORDER BY [c].[CustomerID] ) AS [t] -INNER JOIN ( - SELECT [o].[OrderID], [o].[CustomerID] - FROM [Orders] AS [o] -) AS [t0] ON [t].[CustomerID] = [t0].[CustomerID] +INNER JOIN [Orders] AS [o] ON [t].[CustomerID] = [o].[CustomerID] ORDER BY [t].[CustomerID]"); } @@ -1475,12 +1469,9 @@ public override async Task Reverse_in_join_inner(bool async) await base.Reverse_in_join_inner(async); AssertSql( - @"SELECT [c].[CustomerID], [t].[OrderID] + @"SELECT [c].[CustomerID], [o].[OrderID] FROM [Customers] AS [c] -LEFT JOIN ( - SELECT [o].[OrderID], [o].[CustomerID] - FROM [Orders] AS [o] -) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] ORDER BY [c].[CustomerID]"); } @@ -1491,17 +1482,14 @@ public override async Task Reverse_in_join_inner_with_skip(bool async) AssertSql( @"@__p_0='2' -SELECT [c].[CustomerID], [t0].[OrderID] +SELECT [c].[CustomerID], [t].[OrderID] FROM [Customers] AS [c] LEFT JOIN ( - SELECT [t].[OrderID], [t].[CustomerID] - FROM ( - SELECT [o].[OrderID], [o].[CustomerID] - FROM [Orders] AS [o] - ORDER BY [o].[OrderID] DESC - OFFSET @__p_0 ROWS - ) AS [t] -) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID] + SELECT [o].[OrderID], [o].[CustomerID] + FROM [Orders] AS [o] + ORDER BY [o].[OrderID] DESC + OFFSET @__p_0 ROWS +) AS [t] ON [c].[CustomerID] = [t].[CustomerID] ORDER BY [c].[CustomerID]"); } @@ -1510,12 +1498,9 @@ public override async Task Reverse_in_SelectMany(bool async) await base.Reverse_in_SelectMany(async); AssertSql( - @"SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] + @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] -INNER JOIN ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] -) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] ORDER BY [c].[CustomerID] DESC"); } @@ -1533,13 +1518,10 @@ FROM [Customers] AS [c] ORDER BY [c].[CustomerID] DESC ) AS [t] CROSS APPLY ( - SELECT [t1].[OrderID], [t1].[CustomerID], [t1].[EmployeeID], [t1].[OrderDate] - FROM ( - SELECT TOP(30) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] - WHERE [t].[CustomerID] = [o].[CustomerID] - ORDER BY [o].[OrderID] DESC - ) AS [t1] + SELECT TOP(30) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] + FROM [Orders] AS [o] + WHERE [t].[CustomerID] = [o].[CustomerID] + ORDER BY [o].[OrderID] DESC ) AS [t0] ORDER BY [t].[CustomerID] DESC"); } @@ -1549,13 +1531,10 @@ public override async Task Reverse_in_projection_subquery(bool async) await base.Reverse_in_projection_subquery(async); AssertSql( - @"SELECT [c].[CustomerID], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] + @"SELECT [c].[CustomerID], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] -OUTER APPLY ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] -) AS [t] -ORDER BY [c].[CustomerID], [t].[OrderDate] DESC, [t].[OrderID]"); +OUTER APPLY [Orders] AS [o] +ORDER BY [c].[CustomerID], [o].[OrderDate] DESC, [o].[OrderID]"); } public override async Task Reverse_in_projection_subquery_single_result(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs index 7cb18e992ff..1dd81937eaf 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs @@ -2111,20 +2111,17 @@ FROM [Customers] AS [c] WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID]", // - @"SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [c].[CustomerID] + @"SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate], [c].[CustomerID] FROM [Customers] AS [c] CROSS APPLY ( - SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] - FROM ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] - WHERE [c].[CustomerID] = [o].[CustomerID] - ORDER BY [o].[OrderID] - OFFSET 1 ROWS - ) AS [t] -) AS [t0] + SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] + FROM [Orders] AS [o] + WHERE [c].[CustomerID] = [o].[CustomerID] + ORDER BY [o].[OrderID] + OFFSET 1 ROWS +) AS [t] WHERE [c].[CustomerID] LIKE N'F%' -ORDER BY [c].[CustomerID], [t0].[OrderDate] DESC"); +ORDER BY [c].[CustomerID], [t].[OrderDate] DESC"); } public override async Task Outer_idenfier_correctly_determined_when_doing_include_on_right_side_of_left_join(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs index b240c57bca5..fbe4bbabdeb 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs @@ -1995,17 +1995,14 @@ public override async Task Where_collection_navigation_ToList_Contains(bool asyn AssertSql( @"@__entity_equality_order_0_OrderID='10248' (Nullable = true) -SELECT [c].[CustomerID], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] +SELECT [c].[CustomerID], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] FROM [Customers] AS [c] -LEFT JOIN ( - SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] - FROM [Orders] AS [o0] -) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID] WHERE EXISTS ( SELECT 1 FROM [Orders] AS [o] WHERE ([c].[CustomerID] = [o].[CustomerID]) AND ([o].[OrderID] = @__entity_equality_order_0_OrderID)) -ORDER BY [c].[CustomerID], [t].[OrderID]"); +ORDER BY [c].[CustomerID], [o0].[OrderID]"); } public override async Task Where_collection_navigation_ToArray_Count(bool async) @@ -2030,17 +2027,14 @@ public override async Task Where_collection_navigation_ToArray_Contains(bool asy AssertSql( @"@__entity_equality_order_0_OrderID='10248' (Nullable = true) -SELECT [c].[CustomerID], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] +SELECT [c].[CustomerID], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] FROM [Customers] AS [c] -LEFT JOIN ( - SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] - FROM [Orders] AS [o0] -) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID] WHERE EXISTS ( SELECT 1 FROM [Orders] AS [o] WHERE ([c].[CustomerID] = [o].[CustomerID]) AND ([o].[OrderID] = @__entity_equality_order_0_OrderID)) -ORDER BY [c].[CustomerID], [t].[OrderID]"); +ORDER BY [c].[CustomerID], [o0].[OrderID]"); } public override async Task Where_collection_navigation_AsEnumerable_Count(bool async) @@ -2065,17 +2059,14 @@ public override async Task Where_collection_navigation_AsEnumerable_Contains(boo AssertSql( @"@__entity_equality_order_0_OrderID='10248' (Nullable = true) -SELECT [c].[CustomerID], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] +SELECT [c].[CustomerID], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] FROM [Customers] AS [c] -LEFT JOIN ( - SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] - FROM [Orders] AS [o0] -) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID] WHERE EXISTS ( SELECT 1 FROM [Orders] AS [o] WHERE ([c].[CustomerID] = [o].[CustomerID]) AND ([o].[OrderID] = @__entity_equality_order_0_OrderID)) -ORDER BY [c].[CustomerID], [t].[OrderID]"); +ORDER BY [c].[CustomerID], [o0].[OrderID]"); } public override async Task Where_collection_navigation_ToList_Count_member(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs index 9d40756f927..cf617713a70 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs @@ -2131,12 +2131,9 @@ public override async Task Join_with_order_by_without_skip_or_take(bool async) await base.Join_with_order_by_without_skip_or_take(async); AssertSql( - @"SELECT [t].[Name], [g].[FullName] + @"SELECT [w].[Name], [g].[FullName] FROM [Gears] AS [g] -INNER JOIN ( - SELECT [w].[Name], [w].[OwnerFullName] - FROM [Weapons] AS [w] -) AS [t] ON [g].[FullName] = [t].[OwnerFullName]"); +INNER JOIN [Weapons] AS [w] ON [g].[FullName] = [w].[OwnerFullName]"); } public override async Task Join_with_order_by_without_skip_or_take_nested(bool async) @@ -2144,16 +2141,13 @@ public override async Task Join_with_order_by_without_skip_or_take_nested(bool a await base.Join_with_order_by_without_skip_or_take_nested(async); AssertSql( - @"SELECT [t0].[Name], [t].[FullName] + @"SELECT [w].[Name], [t].[FullName] FROM [Squads] AS [s] INNER JOIN ( SELECT [g].[SquadId], [g].[FullName] FROM [Gears] AS [g] ) AS [t] ON [s].[Id] = [t].[SquadId] -INNER JOIN ( - SELECT [w].[Name], [w].[OwnerFullName] - FROM [Weapons] AS [w] -) AS [t0] ON [t].[FullName] = [t0].[OwnerFullName]"); +INNER JOIN [Weapons] AS [w] ON [t].[FullName] = [w].[OwnerFullName]"); } public override async Task Collection_with_inheritance_and_join_include_joined(bool async) @@ -5331,17 +5325,14 @@ public override async Task Correlated_collection_with_top_level_Last_with_order_ await base.Correlated_collection_with_top_level_Last_with_order_by_on_inner(async); AssertSql( - @"SELECT [t].[Nickname], [t].[SquadId], [t0].[Id], [t0].[AmmunitionType], [t0].[IsAutomatic], [t0].[Name], [t0].[OwnerFullName], [t0].[SynergyWithId] + @"SELECT [t].[Nickname], [t].[SquadId], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM ( SELECT TOP(1) [g].[Nickname], [g].[SquadId], [g].[FullName] FROM [Gears] AS [g] ORDER BY [g].[FullName] DESC ) AS [t] -LEFT JOIN ( - SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] - FROM [Weapons] AS [w] -) AS [t0] ON [t].[FullName] = [t0].[OwnerFullName] -ORDER BY [t].[FullName] DESC, [t].[Nickname], [t].[SquadId], [t0].[Name]"); +LEFT JOIN [Weapons] AS [w] ON [t].[FullName] = [w].[OwnerFullName] +ORDER BY [t].[FullName] DESC, [t].[Nickname], [t].[SquadId], [w].[Name]"); } public override async Task Null_semantics_on_nullable_bool_from_inner_join_subquery_is_fully_applied(bool async) @@ -7044,7 +7035,7 @@ LEFT JOIN [Officers] AS [o0] ON ([g0].[Nickname] = [o0].[Nickname]) AND ([g0].[S WHERE [t2].[row] <= 50 ) AS [t1] ON (([t0].[Nickname] = [t1].[LeaderNickname]) OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND ([t0].[SquadId] = [t1].[LeaderSquadId]) WHERE [t0].[Discriminator] = N'Officer' -ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Nickname], [t1].[SquadId]"); +ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); } public override async Task Project_collection_navigation_nested_composite_key(bool async) @@ -8580,7 +8571,7 @@ FROM [Weapons] AS [w] ) AS [t] WHERE [t].[row] <= 10 ) AS [t0] ON [g].[FullName] = [t0].[OwnerFullName] -ORDER BY [g].[Nickname], [g].[SquadId], [c].[Name], [t0].[OwnerFullName], [t0].[Id]"); +ORDER BY [g].[Nickname], [g].[SquadId], [c].[Name]"); } public override async Task First_on_byte_array(bool async)