Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF.Functions could not be translated and will be evaluated locally when used as key of GroupBy? #12822

Closed
yyjdelete opened this issue Jul 27, 2018 · 4 comments

Comments

@yyjdelete
Copy link

Describe what is not working as expected.

Since #10404 is not available now, I'm trying to use DateDiffDay to get it for groupby, but found EF.Functions also not works for groupby.
EF.Functions could not be translated and will be evaluated locally when used as key of GroupBy?

If you are seeing an exception, include the full exceptions details (message and stack trace).

None

Steps to reproduce

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

dbContext.CommDataDay
                    .GroupBy(d => (EF.Functions.DateDiffDay(new DateTime(2000, 1, 2), d.StartTime) % 7 + 7) % 7)
                    .Select(d => new { Dw = (DayOfWeek)d.Key, Value = d.Sum(d1=>d1.DeltaValue) })
                    .ToList();

dbContext.CommDataDay
                    .Select(d => new { Dw = (EF.Functions.DateDiffDay(new DateTime(2000, 1, 2), d.StartTime) % 7 + 7) % 7, d.DeltaValue })
                    .GroupBy(d => d.Dw)
                    .Select(d => new { Dw = (DayOfWeek)d.Key, Value = d.Sum(d1=>d1.DeltaValue) })
                    .ToList();
Microsoft.EntityFrameworkCore.Query Warn The LINQ expression 'GroupBy((((__Functions_0.DateDiffDay(2000/1/2 0:00:00, [d].StartTime) % 7) + 7) % 7), [d])' could not be translated and will be evaluated locally.

Microsoft.EntityFrameworkCore.Database.Command Info Executed DbCommand (67ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [d].[Start_Time], [d].[Delta_Value]
FROM [Comm_Data_Day] AS [d]
ORDER BY ((DATEDIFF(DAY, '2000-01-02T00:00:00.0000000', [d].[Start_Time]) % 7) + 7) % 7

Further technical details

EF Core version: (found in project.csproj or packages.config)2.1.2
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win10 x64(1803 17134)
IDE: (e.g. Visual Studio 2017 15.4)VS2017 15.8p5

@smitpatel
Copy link
Member

Can you try wrapping up your key into an anonymous type?

@smitpatel
Copy link
Member

Superset of #12476

@yyjdelete
Copy link
Author

wrapping up your key into an anonymous type works for me.

@smitpatel smitpatel reopened this Aug 1, 2018
@smitpatel
Copy link
Member

Duplicate of #12476

@smitpatel smitpatel marked this as a duplicate of #12476 Aug 1, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants