Skip to content

Commit

Permalink
Query: Apply table aliasing recursively
Browse files Browse the repository at this point in the history
We did not visit inner when we updated alias for select expression
  • Loading branch information
smitpatel committed Jun 13, 2019
1 parent 82df078 commit 2474327
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ private readonly ISet<TableExpressionBase> _visitedTableExpressionBases

protected override Expression VisitExtension(Expression extensionExpression)
{
switch (extensionExpression)
var visitedExpression = base.VisitExtension(extensionExpression);
if (visitedExpression is TableExpressionBase tableExpressionBase
&& !_visitedTableExpressionBases.Contains(tableExpressionBase)
&& tableExpressionBase.Alias != null)
{
case TableExpressionBase tableExpressionBase
when !_visitedTableExpressionBases.Contains(tableExpressionBase)
&& tableExpressionBase.Alias != null:
tableExpressionBase.Alias = GenerateUniqueAlias(tableExpressionBase.Alias);
_visitedTableExpressionBases.Add(tableExpressionBase);
return tableExpressionBase;

default:
return base.VisitExtension(extensionExpression);
tableExpressionBase.Alias = GenerateUniqueAlias(tableExpressionBase.Alias);
_visitedTableExpressionBases.Add(tableExpressionBase);
}

return visitedExpression;
}

private string GenerateUniqueAlias(string currentAlias)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4401,7 +4401,7 @@ from l2 in grouping.DefaultIfEmpty()
elementAsserter: (e, a) => Assert.Equal(e.Id, a.Id));
}

[ConditionalTheory(Skip = "QueryIssue")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Explicit_GroupJoin_in_subquery_with_multiple_result_operator_distinct_count_materializes_main_clause(
bool isAsync)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3123,16 +3123,15 @@ public override async Task Explicit_GroupJoin_in_subquery_with_multiple_result_o
await base.Explicit_GroupJoin_in_subquery_with_multiple_result_operator_distinct_count_materializes_main_clause(isAsync);

AssertSql(
@"SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id]
FROM [LevelOne] AS [l1]
@"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id]
FROM [LevelOne] AS [l]
WHERE (
SELECT COUNT(*)
FROM (
SELECT DISTINCT [l1_inner].*
FROM [LevelOne] AS [l1_inner]
LEFT JOIN [LevelTwo] AS [l2] ON [l1_inner].[Id] = [l2].[Level1_Optional_Id]
) AS [t]
) > 4");
SELECT DISTINCT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id]
FROM [LevelOne] AS [l0]
LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id]
) AS [t]) > 4");
}

public override async Task Where_on_multilevel_reference_in_subquery_with_outer_projection(bool isAsync)
Expand Down

0 comments on commit 2474327

Please sign in to comment.