This post show you how to use linq group by count lambda in c#.

You can easily use linq group by count to dictionary as shown below.

var data = from p in db.GroupBy(p => p.DepartmentName)
                        select new
                        {
                             DepartmentName = p.First().DepartmentName,
                             Count = p.Count()
                        };

or you can write linq group by count distinct

var data =
        from p in products
        group p by p.Category into g
        select new { 
                       Category = g.Key,
                       Count = g.Count()
                   };