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 on Navigation Property not translating properly #27077

Open
Tracked by #30173
nomz0101 opened this issue Dec 30, 2021 · 0 comments
Open
Tracked by #30173

GroupBy on Navigation Property not translating properly #27077

nomz0101 opened this issue Dec 30, 2021 · 0 comments

Comments

@nomz0101
Copy link

nomz0101 commented Dec 30, 2021

Hi,

When writing a simple groupBy the query that gets translated adds extra join of the same table when aggregating on navigation property that is also used in the Key.
This does not make sense and causes a lot of performance issues.

C#:

_session.Set<SchoolLoginLocation>()
                .GroupBy(a => new { a.LoginLocation.Id })
                .Select(g => new { g.Key, Cnt = g.Count(a => a.LoginLocation.Id == 1) })
                .ToList();

SQL Translation:

SELECT [l].[Id] AS [LocationId], COUNT(CASE WHEN [l0].[Id] = 1 THEN 1 END) AS [Cnt]
FROM [bdk].[SchoolLoginLocations] AS [s]
**INNER JOIN [bdk].[LoginLocations] AS [l] ON [s].[LoginLocationId] = [l].[Id]
INNER JOIN [bdk].[LoginLocations] AS [l0] ON [s].[LoginLocationId] = [l0].[Id]**
GROUP BY [l].[Id]
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