Answers for "group by in linq and select column with count"

C#
4

linq select count group by c#

foreach(var line in data.GroupBy(info => info.metric)
                        .Select(group => new { 
                             Metric = group.Key, 
                             Count = group.Count() 
                        })
                        .OrderBy(x => x.Metric))
{
     Console.WriteLine("{0} {1}", line.Metric, line.Count);
}
Posted by: Guest on January-22-2021
2

transalations from sql to Linq count and group by

var query = from s in Stock 
            group s by new {s.Id, s.SupId, s.Text, s.ExternalId} into g
            select new {g.Key.Id, g.Key.SupId, g.Key.Text, g.Key.ExternalId, Count = g.Count()};
Posted by: Guest on December-13-2021

Code answers related to "group by in linq and select column with count"

C# Answers by Framework

Browse Popular Code Answers by Language