I am trying to use Aggregate function
Count() on some column using dynamic linq query but I am not able to achieve, what I am exactly looking is
Select Count(Id),Id
from Table1
Group By Id
Having Count(Id) > 1
I want to convert the same query to dynamic linq query, any suggestions on how to achieve this?
The following two queries will give you the exact same result: first with lambda second result without.
var Table1 = new List<Row>();
for (int i = 0; i < 10; i++)
{
for (int m = 0; m < 5; m++)
{
for (int x = 0; x < i + m; x++)
{
Table1.Add(new Row() { Id = m });
}
}
}
var result = Table1.GroupBy(row => row.Id)
.Where(p => p.Count() > 1);
var resultB = from row in Table1
group row by row.Id into rowGrouped
where rowGrouped.Count() > 1
select rowGrouped;
foreach (var r in resultB)
{
Console.WriteLine("ID {0} count: {1}", r.Key, r.Count());
}