Skip to content

Commit

Permalink
UseAlias
Browse files Browse the repository at this point in the history
  • Loading branch information
Suchiman committed Oct 18, 2022
1 parent df614b8 commit 1b995d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,29 @@ public ProjectionIndexRemappingExpressionVisitor(
}
}

private sealed class UseAliasExpressionVisitor : ExpressionVisitor
{
private readonly SelectExpression _queryExpression;

public UseAliasExpressionVisitor(SelectExpression queryExpression)
{
_queryExpression = queryExpression;
}

[return: NotNullIfNotNull("expression")]
public override Expression? Visit(Expression? expression)
{
foreach (var x in _queryExpression.Projection)
{
if (x.Expression.Equals(expression))
{
return new SqlFragmentExpression(x.Alias);
}
}
return base.Visit(expression);
}
}

private sealed class SqlRemappingVisitor : ExpressionVisitor
{
private readonly SelectExpression _subquery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,12 @@ Expression CopyProjectionToOuter(SelectExpression innerSelectExpression, Express
_projectionMapping.Clear();
_projectionMapping = result;

var useAliasVisitor = new UseAliasExpressionVisitor(this);
for (var i = 0; i < _orderings.Count; i++)
{
_orderings[i] = useAliasVisitor.VisitAndConvert(_orderings[i], nameof(ApplyProjection));
}

return shaperExpression;
}

Expand Down

0 comments on commit 1b995d1

Please sign in to comment.