From b315b56ff69ee6cc8f2b0fee2182b86042917bbf Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 15 Aug 2019 15:05:01 -0700 Subject: [PATCH] Query: Fix flaky GroupJoinFlatteningExpressionVisitor Issue: A nested visitor was stored in static field but if contained states which caused flattening to fail some times. Also verified that such issue is not appearing anywhere else in query. --- .../GroupJoinFlatteningExpressionVisitor.cs | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs b/src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs index d862a32442e..9e5e30c766a 100644 --- a/src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs @@ -5,17 +5,16 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using System.Reflection; using Microsoft.EntityFrameworkCore.Internal; namespace Microsoft.EntityFrameworkCore.Query.Internal { public class GroupJoinFlatteningExpressionVisitor : ExpressionVisitor { - private static readonly SelectManyVerifyingExpressionVisitor _selectManyVerifyingExpressionVisitor - = new SelectManyVerifyingExpressionVisitor(); private static readonly EnumerableToQueryableMethodConvertingExpressionVisitor _enumerableToQueryableReMappingExpressionVisitor = new EnumerableToQueryableMethodConvertingExpressionVisitor(); + private readonly SelectManyVerifyingExpressionVisitor _selectManyVerifyingExpressionVisitor + = new SelectManyVerifyingExpressionVisitor(); protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { @@ -34,12 +33,12 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp // GroupJoin var outer = Visit(groupJoinMethod.Arguments[0]); var inner = Visit(groupJoinMethod.Arguments[1]); - var outerKeySelector = UnwrapLambdaFromQuoteExpression(groupJoinMethod.Arguments[2]); - var innerKeySelector = UnwrapLambdaFromQuoteExpression(groupJoinMethod.Arguments[3]); - var groupJoinResultSelector = UnwrapLambdaFromQuoteExpression(groupJoinMethod.Arguments[4]); + var outerKeySelector = groupJoinMethod.Arguments[2].UnwrapLambdaFromQuote(); + var innerKeySelector = groupJoinMethod.Arguments[3].UnwrapLambdaFromQuote(); + var groupJoinResultSelector = groupJoinMethod.Arguments[4].UnwrapLambdaFromQuote(); - var selectManyCollectionSelector = UnwrapLambdaFromQuoteExpression(methodCallExpression.Arguments[1]); - var selectManyResultSelector = UnwrapLambdaFromQuoteExpression(methodCallExpression.Arguments[2]); + var selectManyCollectionSelector = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote(); + var selectManyResultSelector = methodCallExpression.Arguments[2].UnwrapLambdaFromQuote(); var collectionSelectorBody = selectManyCollectionSelector.Body; var defaultIfEmpty = false; @@ -161,11 +160,11 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp // GroupJoin var outer = Visit(groupJoinMethod.Arguments[0]); var inner = Visit(groupJoinMethod.Arguments[1]); - var outerKeySelector = UnwrapLambdaFromQuoteExpression(groupJoinMethod.Arguments[2]); - var innerKeySelector = UnwrapLambdaFromQuoteExpression(groupJoinMethod.Arguments[3]); - var groupJoinResultSelector = UnwrapLambdaFromQuoteExpression(groupJoinMethod.Arguments[4]); + var outerKeySelector = groupJoinMethod.Arguments[2].UnwrapLambdaFromQuote(); + var innerKeySelector = groupJoinMethod.Arguments[3].UnwrapLambdaFromQuote(); + var groupJoinResultSelector = groupJoinMethod.Arguments[4].UnwrapLambdaFromQuote(); - var selectManyResultSelector = UnwrapLambdaFromQuoteExpression(methodCallExpression.Arguments[1]); + var selectManyResultSelector = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote(); var groupJoinResultSelectorBody = groupJoinResultSelector.Body; var defaultIfEmpty = false; @@ -383,8 +382,5 @@ protected override Expression VisitParameter(ParameterExpression parameterExpres return base.VisitParameter(parameterExpression); } } - - private LambdaExpression UnwrapLambdaFromQuoteExpression(Expression expression) - => (LambdaExpression)((UnaryExpression)expression).Operand; } }