-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Must be reducible node System.ArgumentException upgrading to EF Core 2.1.1 #12560
Comments
I got this same issue how can i solve it after migrate from 2.0 to 2.1.1 |
@sokhomhuy - I stayed with 2.0 - don't think there is a workaround in 2.1. The fix is scheduled for 3.0.0. Am I right @maumar ? |
@maumar @smitpatel Any workarounds here? |
@sokhomhuy workaround is to specify ToList call after the groupby. This will basically revert to 2.0 behavior, where we were not trying to client evaluate the groupby. |
The workaround works @maumar . Thanks. |
Works fine @maumar . Thank you. |
In my case, i had a select statement before the groupby function. What worked for me was calling .ToList() after the select function and before the GroupBy() function. |
Similar problem happening to me on 2.2.4. This works:
But I get
What is causing the problem here? Shouldn't the expression compilation results be the same in both cases? |
@vainolo there are number of issues with |
Any ETA for a fix here? |
@vainolo as of now the bug is scheduled for 3.0 release, so (if nothing changes) that should be sometime in September. |
For Googler's, if you try to GroupBy something nested, e.g.
You'll get the following exception:
At least I did on EFCore 3.0.0-preview8. I'm relatively doubtful that this will be fixed by September, given its new status in the backlog. I uploaded an example here. |
@dharmaturtle this specific issue (navigation in GroupBy key) actually has been fixed and should be working when preview9 ships - cb043a2 |
Thanks for the news @maumar. I updated my example repo to the nightly build, and it is currently giving me the error
I believe by having the Here's the full stack trace:
|
@dharmaturtle currently EFCore only supports groupby translation that results in groupby on the server, so the query needs to have some sort of aggregate and/or project a grouping key. Client-side groupby is tracked here: #17068 Sorry about the confusion caused by the initial comment. |
@maumar I believe my code does execute on the server. Here it is again for ease of reference:
This yields the
This does not result in any errors, though likely the Furthermore, if I group by the object and not the
I get the following error:
I believe that the "or switch to client evaluation" supports the idea that my query is running server side. Could you please elaborate on what you mean by "the query needs to have some sort of aggregate and/or project a grouping key"? I believe the Thanks for bearing with me on this. |
The query itself is running on the server. What we mean by "client groupby" is groupby that doesn't directly get translated to the GROUP BY on the server. new EFExampleBugDb().Comment.GroupBy(x => x.PostId) into SELECT * FROM Comments as x GROUP BY x.PostId But this won't work - SQL Server throws the following error:
In order to make the query translatable to group by you need something like this: new EFExampleBugDb().Comment.GroupBy(x => x.PostId).Select(g => new { key = g.Key, aggregate = g.Count() } In order to translate GroupBy query that doesn't have a Select, EF needs to fetch all the data it needs for the query and bucket results into groups on the client. That part is missing and is tracked by #17068. Basically we will do the equivalent of context.Comment.ToList().GroupBy(x => x.PostId). So, looking at the first case:
EF query pipelines encounters GroupBy and determines that it can't fully translate it to server GROUP BY, and that it will need to perform bucketing of groups on the client (i.e. client group by), and for now it throws the error. looking at this example:
EF doesn't see anything that happens after ToList(), so from our perspective the query is just:
that's why you are not seeing any errors here. Wrt group by entity (the last example), its tracked by #15938 |
Ahhh, that makes many things clearer. Thanks for explaining so much @maumar ! |
What if you consider bucketing on the client side to be an inherent part of object-relational mapping rather than client side evaluation? Then group join would fall outside the no-implicit-client-side-evaluation safeguard. If there are a million comments, the developer who writes the query new EFExampleBugDb().Comment.GroupBy(x => x.PostId) expects to pull a million rows from the comment table. Building new EFExampleBugDb().Comment.Select(x => IsSpam(x)) where the developer is expecting 1000 results, but because |
I thought of a downside to my previous post. Even though the grouping isn't expensive, the implicit switch to client-side evaluation can be confusing if the query contains subsequent operations. If the Maybe it's best to recommend that the developer explicitly call |
What I was doing to get around this error was to wrap the server part in a Certainly the errors were not very helpful in debugging it and I had to use SQL Profiler to see what EF Core was generating. |
@smitpatel I'd seen #17068 and considered it in conjunction with this issue. Both seemed to stop at identifying that SQL |
I briefly went over all the queries posted in this issue.
GroupBy queries with aggregates in which Where predicate or Distinct is applied on grouping before calling aggregate operator is being tracked in #17376 #18836 Anything client evaluating will not work as per #17068. If you are getting exception message and if it does not fit in any of the above bucket then please file a new issue. Closing this issue as closed by design since query posted in first post is not something we can translate to server. |
The exception looks similar to #11933 but the query is different and the stack trace is not identical. In case the problem source is unrelated please find the description below.
The following works fine in 2.0.1:
After upgrading to Microsoft.EntityFrameworkCore.SqlServer version 2.1.1 from version 2.0.1, a System.ArgumentException gets thrown with the following message and stack trace.
Commenting out both
Count_lastName = q.Where(item => (1 == group32123533.Key)).Count()
andMin_enrollmentDate = q.Where(item => (1 == group32123533.Key)).Min(item => item.EnrollmentDate)
gets rid of the exception.Steps to reproduce
Create a console application with the following PropertyGroup and ItemGroup:
Add the classes below:
Update the Main method using the code described at the top and run the code.
Further technical details
EF Core version: 2.1.1
Database Provider: SqlServer 2014
Operating system: Windows 10
IDE: Visual Studio 2017 15.7.4
The text was updated successfully, but these errors were encountered: