Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SMALL] Fix to #20759 - Query: client eval followed by aggregate operation throws KeyNotFoundException: The given key 'EmptyProjectionMember' was not present in the dictionary. #20936

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,16 @@ protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression

var newSelector = selector == null
|| selector.Body == selector.Parameters[0]
? selectExpression.GetMappedProjection(new ProjectionMember())
? selectExpression.Projection.Count == 0
? selectExpression.GetMappedProjection(new ProjectionMember())
: null
: RemapLambdaBody(source, selector);

if (newSelector == null)
{
return null;
}

var projection = _sqlTranslator.TranslateAverage(newSelector);
return projection != null
? AggregateResultShaper(source, projection, throwWhenEmpty: true, resultType)
Expand Down Expand Up @@ -683,9 +690,16 @@ protected override ShapedQueryExpression TranslateMax(ShapedQueryExpression sour

var newSelector = selector == null
|| selector.Body == selector.Parameters[0]
? selectExpression.GetMappedProjection(new ProjectionMember())
? selectExpression.Projection.Count == 0
? selectExpression.GetMappedProjection(new ProjectionMember())
: null
: RemapLambdaBody(source, selector);

if (newSelector == null)
{
return null;
}

var projection = _sqlTranslator.TranslateMax(newSelector);

return AggregateResultShaper(source, projection, throwWhenEmpty: true, resultType);
Expand All @@ -701,9 +715,16 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour

var newSelector = selector == null
|| selector.Body == selector.Parameters[0]
? selectExpression.GetMappedProjection(new ProjectionMember())
? selectExpression.Projection.Count == 0
? selectExpression.GetMappedProjection(new ProjectionMember())
: null
: RemapLambdaBody(source, selector);

if (newSelector == null)
{
return null;
}

var projection = _sqlTranslator.TranslateMin(newSelector);

return AggregateResultShaper(source, projection, throwWhenEmpty: true, resultType);
Expand Down Expand Up @@ -1028,11 +1049,19 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour

var selectExpression = (SelectExpression)source.QueryExpression;
selectExpression.PrepareForAggregate();

var newSelector = selector == null
|| selector.Body == selector.Parameters[0]
? selectExpression.GetMappedProjection(new ProjectionMember())
? selectExpression.Projection.Count == 0
? selectExpression.GetMappedProjection(new ProjectionMember())
: null
: RemapLambdaBody(source, selector);

if (newSelector == null)
{
return null;
}

var projection = _sqlTranslator.TranslateSum(newSelector);
return projection != null
? AggregateResultShaper(source, projection, throwWhenEmpty: false, resultType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,11 @@ public override Task Enum_closure_typed_as_underlying_type_generates_correct_par
{
return base.Enum_closure_typed_as_underlying_type_generates_correct_parameter_type(async);
}

[ConditionalTheory(Skip = "issue #17386")]
public override Task Client_eval_followed_by_set_operation_throws_meaningful_exception(bool async)
{
return base.Client_eval_followed_by_set_operation_throws_meaningful_exception(async);
}
}
}
25 changes: 25 additions & 0 deletions test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7481,6 +7481,31 @@ public virtual Task Enum_array_contains(bool async)
.Where(w => w.SynergyWith != null && types.Contains(w.SynergyWith.AmmunitionType)));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Client_eval_followed_by_set_operation_throws_meaningful_exception(bool async)
{
await AssertTranslationFailed(
() => AssertSum(
async,
ss => ss.Set<Mission>().Select(m => m.Duration.Ticks)));

await AssertTranslationFailed(
() => AssertAverage(
async,
ss => ss.Set<Mission>().Select(m => m.Duration.Ticks)));

await AssertTranslationFailed(
() => AssertMin(
async,
ss => ss.Set<Mission>().Select(m => m.Duration.Ticks)));

await AssertTranslationFailed(
() => AssertMax(
async,
ss => ss.Set<Mission>().Select(m => m.Duration.Ticks)));
}

protected GearsOfWarContext CreateContext() => Fixture.CreateContext();

protected virtual void ClearLog()
Expand Down