Skip to content

TimeSpan.TotalHours could not be translatedΒ #1910

@Lyra1337

Description

@Lyra1337

Steps to reproduce

  1. Create a Database:
CREATE DATABASE test1;
USE test1;
CREATE TABLE `test` (
	`Id` INT NOT NULL,
	`Time` TIME NULL,
	PRIMARY KEY (`Id`)
)
COLLATE='utf8mb4_general_ci';
  1. Scaffold new context
  2. Try to sum all values of the Time column

context.Test.Sum(x => x.Time.TotalHours)

neither works:

context.Test.Sum(x => EF.Functions.DateDiffMinute(x.Time.TotalHours, TimeSpan.Zero) / 60d)

The issue

System.InvalidOperationException: The LINQ expression [...] could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

Further technical details

Operating system: Windows / Linux
Pomelo.EntityFrameworkCore.MySql version: 8.0.0
Microsoft.AspNetCore.App version: 8.0.200


So, it's dear to me that TotalHours can't be mapped.
Is there an other way to sum up all time valued-rows?
Can I add the function TIME_TO_SEC to the EF Functions to call it an then divide by 3600 to get the hours?

Any help will be appreciated.

Thank you in advance.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions