From fe43369931be6239004ed32d60a4def3356f858a Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Fri, 25 Oct 2024 19:41:44 +0200 Subject: [PATCH] Recursively visit when normalizing Any/All to Contains Fixes #34984 --- .../Internal/QueryOptimizingExpressionVisitor.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/EFCore/Query/Internal/QueryOptimizingExpressionVisitor.cs b/src/EFCore/Query/Internal/QueryOptimizingExpressionVisitor.cs index 030663bfdcc..293832df4fd 100644 --- a/src/EFCore/Query/Internal/QueryOptimizingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/QueryOptimizingExpressionVisitor.cs @@ -180,13 +180,13 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp if ((methodInfo == EnumerableMethods.AnyWithPredicate || methodInfo == QueryableMethods.AnyWithPredicate) && !negated) { var containsMethod = containsMethodDefinition.MakeGenericMethod(methodCallExpression.Method.GetGenericArguments()[0]); - return Expression.Call(null, containsMethod, methodCallExpression.Arguments[0], itemExpression); + return Visit(Expression.Call(null, containsMethod, methodCallExpression.Arguments[0], itemExpression)); } if ((methodInfo == EnumerableMethods.All || methodInfo == QueryableMethods.All) && negated) { var containsMethod = containsMethodDefinition.MakeGenericMethod(methodCallExpression.Method.GetGenericArguments()[0]); - return Expression.Not(Expression.Call(null, containsMethod, methodCallExpression.Arguments[0], itemExpression)); + return Visit(Expression.Not(Expression.Call(null, containsMethod, methodCallExpression.Arguments[0], itemExpression))); } } } @@ -278,15 +278,6 @@ protected override Expression VisitNewArray(NewArrayExpression newArrayExpressio return newArrayExpression.Update(expressions); } - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - protected override Expression VisitUnary(UnaryExpression unaryExpression) - => unaryExpression.Update(Visit(unaryExpression.Operand)); - private static Expression MatchExpressionType(Expression expression, Type typeToMatch) => expression.Type != typeToMatch ? Expression.Convert(expression, typeToMatch)