efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Cannot Sum Double?

Open dietrichha opened this issue 8 years ago • 2 comments

Hi,

with the new ef core 2.1 I get errors when I try to sum a nullable doube (double?). E.g.:

        var allArrivedTransports = await _context.Transport.Select(t => new
        {
            TotalChargeableWeightPerTransport =
                   t.TransportItems.Sum(ti => ti.ChargeableWeight))
        })
            .ToListAsync();

ChargeableWeight is a nullable doube. One Transport has one to many TransportItems. I get:

System.InvalidOperationException: No coercion operator is defined between types 'System.Threading.Tasks.Task`1[System.Double]' and 'System.Nullable`1[System.Double]'.
   at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
   at System.Linq.Expressions.Expression.Convert(Expression expression, Type type, MethodInfo method)
   at System.Linq.Expressions.Expression.Convert(Expression expression, Type type)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandleSum(HandlerContext handlerContext)

All worked well with 2.0.

kind regards, thanks for the greate work you are doing

Further technical details

EF Core version: 2.1 Database Provider: Postgres Operating system: Windows 10 IDE: Visual Studio 2017 15.Newest

dietrichha avatar Jun 18 '18 15:06 dietrichha

Duplicate of #12314

smitpatel avatar Jun 18 '18 15:06 smitpatel

@maumar - Can you add regression test for this scenario and close the issue?

smitpatel avatar Jun 18 '18 15:06 smitpatel