diff --git a/src/EFCore.Relational/Query/Internal/NullSemanticsRewritingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/NullSemanticsRewritingExpressionVisitor.cs index 8313988ee26..8d9c1f200c8 100644 --- a/src/EFCore.Relational/Query/Internal/NullSemanticsRewritingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/NullSemanticsRewritingExpressionVisitor.cs @@ -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; @@ -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; diff --git a/src/EFCore.Relational/Query/QuerySqlGenerator.cs b/src/EFCore.Relational/Query/QuerySqlGenerator.cs index 2dbb0c227fb..4b605f83b91 100644 --- a/src/EFCore.Relational/Query/QuerySqlGenerator.cs +++ b/src/EFCore.Relational/Query/QuerySqlGenerator.cs @@ -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()) diff --git a/src/EFCore.Relational/Query/SqlExpressionVisitor.cs b/src/EFCore.Relational/Query/SqlExpressionVisitor.cs index c034f4e0f14..bc3ea3cbbfd 100644 --- a/src/EFCore.Relational/Query/SqlExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/SqlExpressionVisitor.cs @@ -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); @@ -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); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs index 8165da6b9a8..e8d05f45e22 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs @@ -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) diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs index bcbcad1b49f..a96ba570ac7 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs @@ -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, @@ -79,7 +79,7 @@ public SqlFunctionExpression( public virtual bool IsNiladic { get; } public virtual bool IsBuiltIn { get; } public virtual IReadOnlyList Arguments { get; } - public virtual Expression Instance { get; } + public virtual SqlExpression Instance { get; } protected override Expression VisitChildren(ExpressionVisitor visitor) { diff --git a/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs b/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs index c206cc7ffe5..f578fc5166b 100644 --- a/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs +++ b/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs @@ -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);