Tushit Nagda Tushit Nagda - 3 months ago 7x
jQuery Question

Write a query for DataTable using LINQ

Current DataTable

Need to Count how many data logged on each day of the week

Desired Output

Whats wrong with this:

var res = from c in dtHour.AsEnumerable()
group c by c.Field<string>("Day Logged") into day
let count = day.Count()
select new {
day_s = day.Count()

The code is not giving the desired output.

var collection = dtHour.AsEnumerable()
      .GroupBy(item => item.Field<string>("Day Logged"))
      .Select(item => new { DayOfWeek = item.Key, Count = item.Count());

To print it the way you wanted:

Console.WriteLine("Day of week - Count");
foreach(var item in collection)
    Console.WriteLine(item.DayOfWeek + " - " + item.Count);