Skip to content

Commit

Permalink
Cleanup in navigation expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
smitpatel committed Jul 1, 2019
1 parent c3225b6 commit 8efc3ad
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,10 @@ private NavigationExpansionExpression VisitSourceExpression(Expression sourceExp
return new NavigationExpansionExpression(result, state, result.Type);
}

private void AdjustCurrentParameterName(
NavigationExpansionExpressionState state,
string newParameterName)
{
if (state.CurrentParameter.Name == null && newParameterName != null)
{
var newParameter = Expression.Parameter(state.CurrentParameter.Type, newParameterName);
state.PendingSelector = (LambdaExpression)new ExpressionReplacingVisitor(state.CurrentParameter, newParameter).Visit(state.PendingSelector);
state.CurrentParameter = newParameter;
}
}

private Expression ProcessWhere(MethodCallExpression methodCallExpression)
{
var source = VisitSourceExpression(methodCallExpression.Arguments[0]);
var predicate = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
AdjustCurrentParameterName(source.State, predicate.Parameters[0].Name);

var appliedNavigationsResult = FindAndApplyNavigations(source.Operand, predicate, source.State);
var newPredicateBody = new NavigationPropertyUnbindingVisitor(appliedNavigationsResult.state.CurrentParameter).Visit(appliedNavigationsResult.lambdaBody);
Expand All @@ -203,7 +190,6 @@ private Expression ProcessSelect(MethodCallExpression methodCallExpression)
{
var source = VisitSourceExpression(methodCallExpression.Arguments[0]);
var selector = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
AdjustCurrentParameterName(source.State, selector.Parameters[0].Name);

return ProcessSelectCore(source.Operand, source.State, selector, methodCallExpression.Type);
}
Expand Down Expand Up @@ -242,7 +228,6 @@ private Expression ProcessOrderBy(MethodCallExpression methodCallExpression)
{
var source = VisitSourceExpression(methodCallExpression.Arguments[0]);
var keySelector = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
AdjustCurrentParameterName(source.State, keySelector.Parameters[0].Name);

var appliedNavigationsResult = FindAndApplyNavigations(source.Operand, keySelector, source.State);
var pendingOrdering = (method: methodCallExpression.Method.GetGenericMethodDefinition(), keySelector: Expression.Lambda(appliedNavigationsResult.lambdaBody, appliedNavigationsResult.state.CurrentParameter));
Expand All @@ -260,7 +245,6 @@ private Expression ProcessThenByBy(MethodCallExpression methodCallExpression)
{
var source = VisitSourceExpression(methodCallExpression.Arguments[0]);
var keySelector = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
AdjustCurrentParameterName(source.State, keySelector.Parameters[0].Name);

var appliedNavigationsResult = FindAndApplyNavigations(source.Operand, keySelector, source.State);

Expand All @@ -277,7 +261,6 @@ private Expression ProcessSelectMany(MethodCallExpression methodCallExpression)
{
var outerSourceNee = VisitSourceExpression(methodCallExpression.Arguments[0]);
var collectionSelector = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
AdjustCurrentParameterName(outerSourceNee.State, collectionSelector.Parameters[0].Name);

var applyNavigationsResult = FindAndApplyNavigations(outerSourceNee.Operand, collectionSelector, outerSourceNee.State);
var applyOrderingsResult = ApplyPendingOrderings(applyNavigationsResult.source, applyNavigationsResult.state);
Expand Down Expand Up @@ -515,9 +498,6 @@ private Expression ProcessJoin(MethodCallExpression methodCallExpression)
var innerKeySelector = methodCallExpression.Arguments[3].UnwrapLambdaFromQuote();
var resultSelector = methodCallExpression.Arguments[4].UnwrapLambdaFromQuote();

AdjustCurrentParameterName(outerSource.State, outerKeySelector.Parameters[0].Name);
AdjustCurrentParameterName(innerSource.State, innerKeySelector.Parameters[0].Name);

var outerApplyNavigationsResult = FindAndApplyNavigations(outerSource.Operand, outerKeySelector, outerSource.State);
var innerApplyNavigationsResult = FindAndApplyNavigations(innerSource.Operand, innerKeySelector, innerSource.State);

Expand Down Expand Up @@ -564,9 +544,6 @@ private Expression ProcessGroupJoin(MethodCallExpression methodCallExpression)
var innerKeySelector = methodCallExpression.Arguments[3].UnwrapLambdaFromQuote();
var resultSelector = methodCallExpression.Arguments[4].UnwrapLambdaFromQuote();

AdjustCurrentParameterName(outerSource.State, outerKeySelector.Parameters[0].Name);
AdjustCurrentParameterName(innerSource.State, innerKeySelector.Parameters[0].Name);

var outerApplyNavigationsResult = FindAndApplyNavigations(outerSource.Operand, outerKeySelector, outerSource.State);
var innerApplyNavigationsResult = FindAndApplyNavigations(innerSource.Operand, innerKeySelector, innerSource.State);

Expand Down Expand Up @@ -672,7 +649,6 @@ private Expression ProcessAll(MethodCallExpression methodCallExpression)
var source = VisitSourceExpression(methodCallExpression.Arguments[0]);
source = RemoveIncludesFromSource(source);
var predicate = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
AdjustCurrentParameterName(source.State, predicate.Parameters[0].Name);

var applyNavigationsResult = FindAndApplyNavigations(source.Operand, predicate, source.State);
var newPredicateBody = new NavigationPropertyUnbindingVisitor(applyNavigationsResult.state.CurrentParameter).Visit(applyNavigationsResult.lambdaBody);
Expand Down Expand Up @@ -747,7 +723,6 @@ private Expression ProcessAverageSumMinMax(MethodCallExpression methodCallExpres
if (methodCallExpression.Arguments.Count == 2)
{
var selector = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
AdjustCurrentParameterName(source.State, selector.Parameters[0].Name);
var applyNavigationsResult = FindAndApplyNavigations(source.Operand, selector, source.State);
var newSelectorBody = new NavigationPropertyUnbindingVisitor(applyNavigationsResult.state.CurrentParameter).Visit(applyNavigationsResult.lambdaBody);
var newSelector = Expression.Lambda(newSelectorBody, applyNavigationsResult.state.CurrentParameter);
Expand Down Expand Up @@ -1083,10 +1058,7 @@ private Expression ProcessInclude(MethodCallExpression methodCallExpression)
methodCallExpression = TryConvertToLambdaInclude(methodCallExpression);

var source = VisitSourceExpression(methodCallExpression.Arguments[0]);

var includeLambda = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
AdjustCurrentParameterName(source.State, includeLambda.Parameters[0].Name);

var applyOrderingsResult = ApplyPendingOrderings(source.Operand, source.State);

// just bind to mark all the necessary navigation for include in the future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5428,7 +5428,7 @@ orderby c.CustomerID
select c.CustomerID);
}

[ConditionalTheory]
[ConditionalTheory(Skip = "Issue#16365")]
[MemberData(nameof(IsAsyncData))]
public virtual Task Comparing_navigations_using_Equals(bool isAsync)
{
Expand Down

0 comments on commit 8efc3ad

Please sign in to comment.