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

GroupBy LINQ Expression could not be translated #9964

Closed
bigswede74 opened this issue Oct 4, 2017 · 8 comments
Closed

GroupBy LINQ Expression could not be translated #9964

bigswede74 opened this issue Oct 4, 2017 · 8 comments

Comments

@bigswede74
Copy link

When executing a group by clause the first time the query runs I get the below exception, but when it runs the second time without error.

Exception message:  The LINQ expression 'GroupBy(new <>f__AnonymousType) could not be translated and will be evaluated
Stack trace:

Steps to reproduce

build a LINQ style group by clause in a entity query

var things = from t in context.Things
                    join t2 in context Thing2 on t.Id equals t2.Id
                    group t by new {  t.ThingName, t2.ThingId   }
                    select new { t.Id, t2.ThingName  }

Further technical details

EF Core version: Microsoft.EntityFrameworkCore version=2.0.0 targetFramework=net47
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows Server 2012 R2 Standard, SQL Server 2014
IDE: Visual Studio 2017

@smitpatel
Copy link
Member

@bigswede74 - Have you configured client evaluation to throw instead of warn? What do you mean running second time? Are you running it second after catching the exception and re-running the same query?

@bigswede74
Copy link
Author

@smitpatel I have not configured the client evaluation to throw, the log is just from the EntityFramework logger so I have no control of the log level. The second the time the query is called it succeeds which is the oddest thing.

@smitpatel
Copy link
Member

@bigswede74 - Can you share whole log? & also your DbContext registration (or OnConfiguring method).

The error is normal warning we generate when we are client evaluating something in query pipeline. It would throw exception only if client eval is configured to throw.
In the same app run it would run without exception second time because EF would use the compiled query from cache and above warning is during compilation phase.

@bigswede74
Copy link
Author

@smitpatel it only happens on the Windows Server 2012 R2, the warning is not seen on my Windows 10 Dev Box.

@smitpatel
Copy link
Member

At this point we would need a repro. Warning will be there since group by cannot be translated to server. But it should be warning regardless of OS.

@ajcvickers
Copy link
Member

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

@mchenx
Copy link

mchenx commented Feb 20, 2018

I got this issue as well

something like this

     var groupedCounts = (from t in _dbContext.VoteTickets
                            join m in _dbContext.VoteItemData
                            on t.VoteItemId equals m.Id
                            where m.City == city
                            group t by m.District into grp
                            select new
                            {
                                District = grp.Key,
                                Count = grp.Count()
                            })
                          .ToArray();

in the output it says GroupBy cannot be translated and will be evaluated locally.
Thus the performance becomes really bad as I have around a million records in the VoteTickets table.

Using Microsoft.EntityframeworkCore.SqlServer v2.0.1

I can see this will be supported in v2.1, #2341, but...it's planed in Q2, still got a few months to wait.

@smitpatel
Copy link
Member

@mchenx - The 2.1 preview would be out soon or you can use nightly builds.

@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

4 participants