This question is locked. New answers and comments are not allowed.
"GroupBy with Conditional Count" doesn't work.
We can see it in LINQ Project Sample Query Explorer:
public object LinqToOpenAccessGroupBy07()
{
var q = from p in scope.Extent<Product>()
group p by p.Category.CategoryID into g
select new
{
g.Key,
NumProducts = g.Count(p => p.Discontinued)
};
return q.ToList();
}
1: SELECT b.[CategoryID] AS COL1, COUNT(a.[Discontinued]) AS EXPR2 FROM [Products] a LEFT JOIN [Categories] AS b ON (a.[CategoryID] = b.[CategoryID]) GROUP BY b.[CategoryID]
p => p.Discontinued condition transforms simply to a.[Discontinued] inside COUNT function in output query. Furthermore, if we have more complicate condition, f.e. dummy p => p.Discontinued && p.Discontinued, the output sql would contain invalid clause COUNT(a.[Discontinued] AND a.[Discontinued])
Does exist any workarround?
We can see it in LINQ Project Sample Query Explorer:
public object LinqToOpenAccessGroupBy07()
{
var q = from p in scope.Extent<Product>()
group p by p.Category.CategoryID into g
select new
{
g.Key,
NumProducts = g.Count(p => p.Discontinued)
};
return q.ToList();
}
1: SELECT b.[CategoryID] AS COL1, COUNT(a.[Discontinued]) AS EXPR2 FROM [Products] a LEFT JOIN [Categories] AS b ON (a.[CategoryID] = b.[CategoryID]) GROUP BY b.[CategoryID]
p => p.Discontinued condition transforms simply to a.[Discontinued] inside COUNT function in output query. Furthermore, if we have more complicate condition, f.e. dummy p => p.Discontinued && p.Discontinued, the output sql would contain invalid clause COUNT(a.[Discontinued] AND a.[Discontinued])
Does exist any workarround?