Skip to content

Commit

Permalink
Return null from Min/Max/Average when nullable type and no rows
Browse files Browse the repository at this point in the history
Fixes #16542
  • Loading branch information
ajcvickers committed Aug 6, 2019
1 parent a401a94 commit 8ba9f17
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,22 @@ private ShapedQueryExpression AggregateResultShaper(

Expression shaper = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), projection.Type);

if (throwOnNullResult)
if (throwOnNullResult
&& resultType.IsNullableType())
{
var resultVariable = Expression.Variable(projection.Type, "result");

shaper = Expression.Block(
new[] { resultVariable },
Expression.Assign(resultVariable, shaper),
Expression.Condition(
Expression.Equal(resultVariable, Expression.Default(projection.Type)),
Expression.Constant(null, resultType),
resultType != resultVariable.Type
? Expression.Convert(resultVariable, resultType)
: (Expression)resultVariable));
}
else if (throwOnNullResult)
{
var resultVariable = Expression.Variable(projection.Type, "result");

Expand Down
Loading

0 comments on commit 8ba9f17

Please sign in to comment.