Skip to content

Commit 507e7f1

Browse files
authored
Use the proper type mapping for the result of AVG (#35023)
Fixes #26378
1 parent 17ed217 commit 507e7f1

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ private ShapedQueryExpression CreateShapedQueryExpression(SelectExpression selec
459459
}
460460

461461
var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
462-
projection = _sqlExpressionFactory.Function("AVG", new[] { projection }, projection.Type, projection.TypeMapping);
462+
projection = _sqlExpressionFactory.Function("AVG", new[] { projection }, resultType, _typeMappingSource.FindMapping(resultType));
463463

464464
return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType);
465465
}

test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -699,22 +699,19 @@ public override async Task Min_no_data_subquery(bool async)
699699
AssertSql();
700700
}
701701

702-
public override async Task Average_with_no_arg(bool async)
703-
{
704-
// Always throws for sync.
705-
if (async)
706-
{
707-
// Average truncates. Issue #26378.
708-
await Assert.ThrowsAsync<EqualException>(async () => await base.Average_with_no_arg(async));
702+
public override Task Average_with_no_arg(bool async)
703+
=> Fixture.NoSyncTest(
704+
async, async a =>
705+
{
706+
await base.Average_with_no_arg(a);
709707

710-
AssertSql(
711-
"""
708+
AssertSql(
709+
"""
712710
SELECT VALUE AVG(c["OrderID"])
713711
FROM root c
714712
WHERE (c["$type"] = "Order")
715713
""");
716-
}
717-
}
714+
});
718715

719716
public override Task Average_with_binary_expression(bool async)
720717
=> Fixture.NoSyncTest(
@@ -730,22 +727,19 @@ FROM root c
730727
""");
731728
});
732729

733-
public override async Task Average_with_arg(bool async)
734-
{
735-
// Always throws for sync.
736-
if (async)
737-
{
738-
// Average truncates. Issue #26378.
739-
await Assert.ThrowsAsync<EqualException>(async () => await base.Average_with_arg(async));
730+
public override Task Average_with_arg(bool async)
731+
=> Fixture.NoSyncTest(
732+
async, async a =>
733+
{
734+
await base.Average_with_arg(a);
740735

741-
AssertSql(
742-
"""
736+
AssertSql(
737+
"""
743738
SELECT VALUE AVG(c["OrderID"])
744739
FROM root c
745740
WHERE (c["$type"] = "Order")
746741
""");
747-
}
748-
}
742+
});
749743

750744
public override Task Average_with_arg_expression(bool async)
751745
=> Fixture.NoSyncTest(

0 commit comments

Comments
 (0)