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

Query: Server Eval Count of GroupBy #15097

Closed
myjimmyzhou opened this issue Mar 21, 2019 · 7 comments · Fixed by #21623
Closed

Query: Server Eval Count of GroupBy #15097

myjimmyzhou opened this issue Mar 21, 2019 · 7 comments · Fixed by #21623
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-bug
Milestone

Comments

@myjimmyzhou
Copy link

myjimmyzhou commented Mar 21, 2019

code:

        public int Count()
        {
            return webUserDao.DbSet().Where(u => u.CreateTime < DateTime.Now).GroupBy(g => g.UserType).Count();
        }

Issues:
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'GroupBy([u].UserType, [u])' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Count()' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Count()' could not be translated and will be evaluated locally.

@MaklaCof
Copy link

Same problem here:

var group = this.Set<DbMasterUser>().GroupBy(t => t.LanguageId).ToArray();

The LINQ expression 'GroupBy([t].LanguageId, [t])' could not be translated and will be evaluated locally.

with

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.3" />

@smitpatel
Copy link
Member

@MaklaCof - Your groupby query lacks aggregate operator. It can never be translated to SQL GROUP BY clause.

@smitpatel
Copy link
Member

@myjimmyzhou - Essentially you are counting number of groups. You can just do Distinct on grouping key column and Count on rather than using GroupBy.

@ajcvickers ajcvickers added this to the 3.0.0 milestone Mar 22, 2019
@smitpatel smitpatel changed the title GroupBy in EF CORE 2.2 Query: Server Eval Count of GroupBy Mar 27, 2019
@divega divega modified the milestones: 3.0.0, Backlog Jun 21, 2019
@smitpatel smitpatel removed their assignment Jun 24, 2019
@smitpatel smitpatel added the verify-fixed This issue is likely fixed in new query pipeline. label Jul 2, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 3.1.0 Sep 4, 2019
@smitpatel smitpatel self-assigned this Sep 12, 2019
@smitpatel
Copy link
Member

Generated invalid SQL

SELECT COUNT(*)
FROM (
    SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
    FROM [Orders] AS [o]
    GROUP BY [o].[CustomerID]
) AS [t]

@smitpatel smitpatel removed the verify-fixed This issue is likely fixed in new query pipeline. label Sep 20, 2019
@smitpatel smitpatel modified the milestones: 3.1.0, Backlog Sep 20, 2019
@smitpatel
Copy link
Member

Work-around

public int Count()
        {
            return webUserDao.DbSet().Where(u => u.CreateTime < DateTime.Now).GroupBy(g => g.UserType).Select(g => g.Key).Count();
        }

@smitpatel smitpatel removed their assignment Nov 12, 2019
@smitpatel
Copy link
Member

Operators covered here

  • Count
  • LongCount
  • Any
  • All

@smitpatel smitpatel self-assigned this Jul 14, 2020
@smitpatel
Copy link
Member

Pulling this in 5.0

@smitpatel smitpatel removed this from the Backlog milestone Jul 14, 2020
@smitpatel smitpatel added this to the 5.0.0 milestone Jul 14, 2020
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 14, 2020
smitpatel added a commit that referenced this issue Jul 14, 2020
smitpatel added a commit that referenced this issue Jul 15, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview8 Jul 15, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview8, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants