Skip to content

Commit

Permalink
Query: Translate GroupBy-Aggregate when using result selector (#18415)
Browse files Browse the repository at this point in the history
* Query: Translate GroupBy-Aggregate when using result selector

Resolves #18267
  • Loading branch information
smitpatel authored Oct 17, 2019
1 parent 2a39b06 commit 0fd7de0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,12 @@ protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression
return source;
}

var keyAccessExpression = Expression.MakeMemberAccess(
source.ShaperExpression,
source.ShaperExpression.Type.GetTypeInfo().GetMember(nameof(IGrouping<int, int>.Key))[0]);

var original1 = resultSelector.Parameters[0];
var original2 = resultSelector.Parameters[1];

var newResultSelectorBody = new ReplacingExpressionVisitor(
new Dictionary<Expression, Expression> {
{ original1, keyAccessExpression },
{ original1, ((GroupByShaperExpression)source.ShaperExpression).KeySelector },
{ original2, source.ShaperExpression }
}).Visit(resultSelector.Body);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,13 @@ protected override ShapedQueryExpression TranslateGroupBy(
return source;
}

var keyAccessExpression = Expression.MakeMemberAccess(
source.ShaperExpression,
source.ShaperExpression.Type.GetTypeInfo().GetMember(nameof(IGrouping<int, int>.Key))[0]);

var original1 = resultSelector.Parameters[0];
var original2 = resultSelector.Parameters[1];

var newResultSelectorBody = new ReplacingExpressionVisitor(
new Dictionary<Expression, Expression>
{
{ original1, keyAccessExpression }, { original2, source.ShaperExpression }
{ original1, translatedKey }, { original2, source.ShaperExpression }
})
.Visit(resultSelector.Body);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7802,7 +7802,7 @@ from g in ss.Set<Gear>()
elementSorter: e => (e.Name, e.Count, e.Sum));
}

[ConditionalTheory(Skip = "issue #18267")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_GroupBy_after_set_operator_using_result_selector(bool isAsync)
{
Expand Down

0 comments on commit 0fd7de0

Please sign in to comment.