Skip to content

Commit

Permalink
Add quirk for issue18299
Browse files Browse the repository at this point in the history
  • Loading branch information
smitpatel committed Feb 14, 2020
1 parent 5cf9658 commit 0fbd787
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/EFCore.Relational/Query/SqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,26 +508,41 @@ private void AddConditions(

if (!skipJoins)
{
var first = true;

foreach (var foreignKey in linkingFks)
if (AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue18299", out var isEnabled) && isEnabled)
{
if (!(entityType.FindOwnership() == foreignKey
&& foreignKey.PrincipalEntityType.BaseType == null))
AddInnerJoin(selectExpression, linkingFks[0], sharingTypes, skipInnerJoins: false);

foreach (var otherFk in linkingFks.Skip(1))
{
var otherSelectExpression = first
? selectExpression
: new SelectExpression(entityType);
var otherSelectExpression = new SelectExpression(entityType);

AddInnerJoin(otherSelectExpression, foreignKey, sharingTypes, skipInnerJoins: false);
AddInnerJoin(otherSelectExpression, otherFk, sharingTypes, skipInnerJoins: false);
selectExpression.ApplyUnion(otherSelectExpression, distinct: true);
}
}
else
{
var first = true;

if (first)
{
first = false;
}
else
foreach (var foreignKey in linkingFks)
{
if (!(entityType.FindOwnership() == foreignKey
&& foreignKey.PrincipalEntityType.BaseType == null))
{
selectExpression.ApplyUnion(otherSelectExpression, distinct: true);
var otherSelectExpression = first
? selectExpression
: new SelectExpression(entityType);

AddInnerJoin(otherSelectExpression, foreignKey, sharingTypes, skipInnerJoins: false);

if (first)
{
first = false;
}
else
{
selectExpression.ApplyUnion(otherSelectExpression, distinct: true);
}
}
}
}
Expand Down

0 comments on commit 0fbd787

Please sign in to comment.