Skip to content

Commit

Permalink
Fix to #18522 - Query: SqlFunctionExpression instance should be SqlEx…
Browse files Browse the repository at this point in the history
…pression rather than Expression

Resolves #18522
  • Loading branch information
maumar committed Nov 19, 2019
1 parent 8483951 commit 5385755
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ protected override Expression VisitRowNumber(RowNumberExpression rowNumberExpres
return rowNumberExpression.Update(partitions, orderings);
}

protected override Expression VisitScalarSubquery(ScalarSubqueryExpression scalarSubqueryExpression)
{
var canOptimize = _canOptimize;
_canOptimize = false;
var subquery = (SelectExpression)Visit(scalarSubqueryExpression.Subquery);
_canOptimize = canOptimize;

return scalarSubqueryExpression.Update(subquery);
}

protected override Expression VisitSelect(SelectExpression selectExpression)
{
var changed = false;
Expand Down Expand Up @@ -584,16 +594,6 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlCastExpression
return sqlCastExpression.Update(newOperand);
}

protected override Expression VisitSubSelect(ScalarSubqueryExpression scalarSubqueryExpression)
{
var canOptimize = _canOptimize;
_canOptimize = false;
var subquery = (SelectExpression)Visit(scalarSubqueryExpression.Subquery);
_canOptimize = canOptimize;

return scalarSubqueryExpression.Update(subquery);
}

protected override Expression VisitTable(TableExpression tableExpression)
=> tableExpression;

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Query/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ protected override Expression VisitLeftJoin(LeftJoinExpression leftJoinExpressio
return leftJoinExpression;
}

protected override Expression VisitSubSelect(ScalarSubqueryExpression scalarSubqueryExpression)
protected override Expression VisitScalarSubquery(ScalarSubqueryExpression scalarSubqueryExpression)
{
_relationalCommandBuilder.AppendLine("(");
using (_relationalCommandBuilder.Indent())
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore.Relational/Query/SqlExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ protected override Expression VisitExtension(Expression extensionExpression)
case SqlParameterExpression sqlParameterExpression:
return VisitSqlParameter(sqlParameterExpression);

case ScalarSubqueryExpression subSelectExpression:
return VisitSubSelect(subSelectExpression);
case ScalarSubqueryExpression scalarSubqueryExpression:
return VisitScalarSubquery(scalarSubqueryExpression);

case TableExpression tableExpression:
return VisitTable(tableExpression);
Expand Down Expand Up @@ -110,14 +110,14 @@ protected override Expression VisitExtension(Expression extensionExpression)
protected abstract Expression VisitOuterApply(OuterApplyExpression outerApplyExpression);
protected abstract Expression VisitProjection(ProjectionExpression projectionExpression);
protected abstract Expression VisitRowNumber(RowNumberExpression rowNumberExpression);
protected abstract Expression VisitScalarSubquery(ScalarSubqueryExpression scalarSubqueryExpression);
protected abstract Expression VisitSelect(SelectExpression selectExpression);
protected abstract Expression VisitSqlBinary(SqlBinaryExpression sqlBinaryExpression);
protected abstract Expression VisitSqlConstant(SqlConstantExpression sqlConstantExpression);
protected abstract Expression VisitSqlFragment(SqlFragmentExpression sqlFragmentExpression);
protected abstract Expression VisitSqlFunction(SqlFunctionExpression sqlFunctionExpression);
protected abstract Expression VisitSqlParameter(SqlParameterExpression sqlParameterExpression);
protected abstract Expression VisitSqlUnary(SqlUnaryExpression sqlCastExpression);
protected abstract Expression VisitSubSelect(ScalarSubqueryExpression scalarSubqueryExpression);
protected abstract Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpression);
protected abstract Expression VisitTable(TableExpression tableExpression);
protected abstract Expression VisitUnion(UnionExpression unionExpression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public override void Print(ExpressionPrinter expressionPrinter)
public override bool Equals(object obj)
=> obj != null
&& (ReferenceEquals(this, obj)
|| obj is ScalarSubqueryExpression subSelectExpression
&& Equals(subSelectExpression));
|| obj is ScalarSubqueryExpression scalarSubqueryExpression
&& Equals(scalarSubqueryExpression));

private bool Equals(ScalarSubqueryExpression scalarSubqueryExpression)
=> base.Equals(scalarSubqueryExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static SqlFunctionExpression Create(
=> new SqlFunctionExpression(instance: null, schema, name, niladic: false, arguments, builtIn: false, type, typeMapping);

public SqlFunctionExpression(
Expression instance,
SqlExpression instance,
string schema,
string name,
bool niladic,
Expand All @@ -79,7 +79,7 @@ public SqlFunctionExpression(
public virtual bool IsNiladic { get; }
public virtual bool IsBuiltIn { get; }
public virtual IReadOnlyList<SqlExpression> Arguments { get; }
public virtual Expression Instance { get; }
public virtual SqlExpression Instance { get; }

protected override Expression VisitChildren(ExpressionVisitor visitor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ protected override Expression VisitLeftJoin(LeftJoinExpression leftJoinExpressio
return leftJoinExpression.Update(table, joinPredicate);
}

protected override Expression VisitSubSelect(ScalarSubqueryExpression scalarSubqueryExpression)
protected override Expression VisitScalarSubquery(ScalarSubqueryExpression scalarSubqueryExpression)
{
var parentSearchCondition = _isSearchCondition;
var subquery = (SelectExpression)Visit(scalarSubqueryExpression.Subquery);
Expand Down

0 comments on commit 5385755

Please sign in to comment.