We're updating the issue view to help you get more done. 

Very weak support for predicates in Linq Aggregate functions

Description

The Linq aggregate functions (Count,Sum etc.) all support certain kinds of predicates or value selectors, but this is very weakly supported. The worst is the Count, which just throws away the predicate.

1 2 3 4 5 var result = db.Products .GroupBy(x => x.Supplier.CompanyName) .Where(x => x.Count(y => y.UnitPrice == 12.75M) == 1) .Select(x => new { x.Key, Count = x.Count() }) .First();

should result in something like

1 2 3 4 5 6 7 8 9 10 select TOP (1) supplier1_.CompanyName as col_0_0_, cast(count(*) as INT) as col_1_0_ from Products product0_ left outer join Suppliers supplier1_ on product0_.SupplierId = supplier1_.SupplierId group by supplier1_.CompanyName having cast(count(cast(case when product0_.UnitPrice = 12.75 then 1 else null end as INT)) as INT) = 1

but becomes

1 2 3 4 5 6 7 select TOP (1) supplier1_.CompanyName as col_0_0_, cast(count(*) as INT) as col_1_0_ from Products product0_ left outer join Suppliers supplier1_ on product0_.SupplierId = supplier1_.SupplierId group by supplier1_.CompanyName having cast(count(*) as INT) = 1

Environment

None

Status

Assignee

Alexander Zaytsev

Reporter

Gunnar Liljas

Components

Fix versions

Affects versions

4.0.2

Priority

Major