Skip to content

'AS' in group by statement when an 'AS' is present in the select statement #11218

Closed

Description

@yepeekai
Emploi
{
    public int EmployeurId {get; set;}
    public Employeur Employeur {get;set;}
...
}

Employeur
{
    public int Id {get; set;}
    public string NomCourt {get;set;}
... 
}

EF uses Emploi.EmployeurId instead of Emploi.Employeur.Id which is ok. It renames it in the query with 'AS' statement. The problem is that the statement get copied in the group by clause with the 'AS' in it.

emploiQuery
.GroupBy(e => new { e.Employeur.Id, e.Employeur.NomCourt })
.Select(grp => new { Value = grp.Key.Id, Label = grp.Key.NomCourt, Count = grp.Count() })

This generates the following query:

SELECT [e].[EmployeurId] AS [Id], [e.Employeur].[NomCourt], COUNT(*)
FROM [Emploi] AS [e]
INNER JOIN [Employeur] AS [e.Employeur] ON [e].[EmployeurId] = [e.Employeur].[Id]
GROUP BY [e].[EmployeurId] AS [Id], [e.Employeur].[NomCourt]

Activity

  1. added this to the 2.1.0 milestone on Mar 9, 2018
  2. added 5 commits that reference this issue on Mar 13, 2018
    b95111c
    2a1c7b1
    e8ca357
    6cf774e
    5b6e178
  3. modified the milestones: , 2.1.0 on Nov 11, 2019
  4. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions