diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs index 9b446a78152..80f90b8574a 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs @@ -459,7 +459,7 @@ private ShapedQueryExpression CreateShapedQueryExpression(SelectExpression selec } var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember()); - projection = _sqlExpressionFactory.Function("AVG", new[] { projection }, projection.Type, projection.TypeMapping); + projection = _sqlExpressionFactory.Function("AVG", new[] { projection }, resultType, _typeMappingSource.FindMapping(resultType)); return AggregateResultShaper(source, projection, throwOnNullResult: true, resultType); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs index 2d30fc87c90..c5a415fb1b9 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs @@ -699,22 +699,19 @@ public override async Task Min_no_data_subquery(bool async) AssertSql(); } - public override async Task Average_with_no_arg(bool async) - { - // Always throws for sync. - if (async) - { - // Average truncates. Issue #26378. - await Assert.ThrowsAsync(async () => await base.Average_with_no_arg(async)); + public override Task Average_with_no_arg(bool async) + => Fixture.NoSyncTest( + async, async a => + { + await base.Average_with_no_arg(a); - AssertSql( - """ + AssertSql( + """ SELECT VALUE AVG(c["OrderID"]) FROM root c WHERE (c["$type"] = "Order") """); - } - } + }); public override Task Average_with_binary_expression(bool async) => Fixture.NoSyncTest( @@ -730,22 +727,19 @@ FROM root c """); }); - public override async Task Average_with_arg(bool async) - { - // Always throws for sync. - if (async) - { - // Average truncates. Issue #26378. - await Assert.ThrowsAsync(async () => await base.Average_with_arg(async)); + public override Task Average_with_arg(bool async) + => Fixture.NoSyncTest( + async, async a => + { + await base.Average_with_arg(a); - AssertSql( - """ + AssertSql( + """ SELECT VALUE AVG(c["OrderID"]) FROM root c WHERE (c["$type"] = "Order") """); - } - } + }); public override Task Average_with_arg_expression(bool async) => Fixture.NoSyncTest(