Skip to content

Nested Count statement with predicate is translated to COUNT(*) #18882

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
prodenx opened this issue Nov 13, 2019 · 2 comments
Closed

Nested Count statement with predicate is translated to COUNT(*) #18882

prodenx opened this issue Nov 13, 2019 · 2 comments

Comments

@prodenx
Copy link

prodenx commented Nov 13, 2019

I have query with several Counts nested in Select statement after GroupBy. Generated SQL does not have conditions in COUNT statement and returns wrong result

Steps to reproduce

 _repository.Where(product => product.Date >= date).GroupBy(product => product.ShiftId).OrderBy(shiftGroup => shiftGroup.Key).Select(shiftGroup =>
                    new
                    {
                        A = shiftGroup .Count(i => i.ReviewStateId == ProductReviewState.Good),
                        B = shiftGroup .Count(i =>
                            i.ReviewStateId != ProductReviewState.NotReviewed &&
                            i.ReviewStateId != ProductReviewState.Skipped),
                        C = shiftGroup .Count()
                    }).ToListAsync()

Fields A, B and C have same value in result.

Generated SQL

SELECT COUNT(*) AS [A], COUNT(*) AS [B], COUNT(*) AS [C]
FROM [Products] AS [s]
WHERE (([s].[Date] >= @__Date_0)
GROUP BY [s].[ShiftId]
ORDER BY [s].[ShiftId]

Further technical details

EF Core version: v3.1.0-preview2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.1
Operating system: Windows 10
IDE: Visual Studio 2019 16.3.8

@hamedmaleki1366
Copy link

hamedmaleki1366 commented Nov 13, 2019

also for me : this Issue

@smitpatel
Copy link
Contributor

Fixed in #18553

@smitpatel smitpatel added this to the 3.1.0 milestone Nov 13, 2019
@smitpatel smitpatel self-assigned this Nov 13, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants