-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SelectMany in linq look something like following (second clause is considered the collection selector) ```C# from c in cs from o in c.Orders select.... ``` Following are the translations of SelectMany Unrelated collection selector ```C# from c in cs from o in os ``` Generates CROSS JOIN Correlated collection selector with correlation being a predicate ```C# from c in cs from o in os.Where(o => o.CustomerID == c.CustomerID) ``` Such predicate can be lifted and used in generating a join. So this query generates JOIN. If collection selector ends with DefaultIfEmpty then it is LEFT JOIN. Correlated collection selector with correlation not a predicate ```C# from c in cs from o in os.Select(o => c.City) ``` Since we cannot generate a join predicate here, this translates to CROSS APPLY. If collection selector ends with DefaultIfEmpty then it is OUTER APPLY. Add support for Cross Apply Add Support for Outer Apply Convert Cross Apply to Inner Join when possible Convert Outer Apply to Left Join when possible Add translation for DefaultIfEmpty Add translation for both overloads of SelectMany Handle DefaultIfEmpty & SelectMany without collectionSelector in Navigation Expansion Ensure columns are in projection when generating join predicate from a correlated subquery Currently there are no tests for Cross/Outer Apply. Our earlier Cross Apply got converted to join. N+1 evaluation tests are disabled right now, which would generate Cross Apply. We never supported Outer Apply in past. Resolves #15711 Resolves #12567 Resolves #12572 Resolves #12872 Resolves #16330 Resolves #15081 Resolves #16989 Re-enable tests for #12449
- Loading branch information
Showing
46 changed files
with
1,331 additions
and
981 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions | ||
{ | ||
public class CrossApplyExpression : JoinExpressionBase | ||
{ | ||
public CrossApplyExpression(TableExpressionBase table) | ||
: base(table) | ||
{ | ||
} | ||
|
||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
=> Update((TableExpressionBase)visitor.Visit(Table)); | ||
|
||
public virtual CrossApplyExpression Update(TableExpressionBase table) | ||
=> table != Table | ||
? new CrossApplyExpression(table) | ||
: this; | ||
|
||
public override void Print(ExpressionPrinter expressionPrinter) | ||
{ | ||
expressionPrinter.StringBuilder.Append("CROSS APPLY "); | ||
expressionPrinter.Visit(Table); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
=> obj != null | ||
&& (ReferenceEquals(this, obj) | ||
|| obj is CrossApplyExpression crossApplyExpression | ||
&& Equals(crossApplyExpression)); | ||
|
||
private bool Equals(CrossApplyExpression crossApplyExpression) | ||
=> base.Equals(crossApplyExpression); | ||
|
||
public override int GetHashCode() => base.GetHashCode(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Linq.Expressions; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions | ||
{ | ||
public class OuterApplyExpression : JoinExpressionBase | ||
{ | ||
public OuterApplyExpression(TableExpressionBase table) | ||
: base(table) | ||
{ | ||
} | ||
|
||
protected override Expression VisitChildren(ExpressionVisitor visitor) | ||
=> Update((TableExpressionBase)visitor.Visit(Table)); | ||
|
||
public virtual OuterApplyExpression Update(TableExpressionBase table) | ||
=> table != Table | ||
? new OuterApplyExpression(table) | ||
: this; | ||
|
||
public override void Print(ExpressionPrinter expressionPrinter) | ||
{ | ||
expressionPrinter.StringBuilder.Append("OUTER APPLY "); | ||
expressionPrinter.Visit(Table); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
=> obj != null | ||
&& (ReferenceEquals(this, obj) | ||
|| obj is OuterApplyExpression outerApplyExpression | ||
&& Equals(outerApplyExpression)); | ||
|
||
private bool Equals(OuterApplyExpression outerApplyExpression) | ||
=> base.Equals(outerApplyExpression); | ||
|
||
public override int GetHashCode() => base.GetHashCode(); | ||
} | ||
} |
Oops, something went wrong.