Efcore.pg: GroupBy and Count with predicate generates incorrect SQL

Created on 23 Oct 2019  路  4Comments  路  Source: npgsql/efcore.pg

Using 3.0.1

ctx.SnatchJobs
    .GroupBy(sj => sj.PaymentDate)
    .Select(g => new 
    {
        NrCancelled = g.Count(sj => sj.Status == SnatchJobStatus.Cancelled),
        NrFailed = g.Count(sj => sj.Status == SnatchJobStatus.Failed)
    }).ToList();

generates

      SELECT COUNT(*)::INT AS "NrCancelled", COUNT(*)::INT AS "NrFailed"
      FROM "SnatchJob" AS l
      GROUP BY l."PaymentDate"

The count predicates are lost.

Most helpful comment

All 4 comments

/cc @smitpatel

Duplicate of https://github.com/aspnet/EntityFrameworkCore/issues/11711

Can throw exception rather than silent ignore.

@smitpatel thanks. Definitely makes sense to throw rather than return incorrect results... New issue for 3.1?

Was this page helpful?
0 / 5 - 0 ratings