c# - Grouping in Linq with TimeSpan.Hours -


i have datatable has following columns

calltime   calltype  15:45:00    voice 15:30:54    voice 00:12:14    sms 01:13:47    voice 05:48:23    sms 12:00:47    voice 

now want using linq result this

hrs   count 00    1 01    1 02    0 03    0 04    0 05    1 06    0 | | | 12    1 13    0 | 15    2 16    0 | | 23    0 

i using following query gives me values having count > 0 wanna having count = 0

var groupquerytimetotal = (from r in foundrows.asenumerable()                                    let time = timespan.parse(r.field<string>("call time"))                                    group r time.hours                                        g                                        select new                                        {                                            calltime = g.key,                                            callcount = g.count(),                                        }).orderby(s => s.calltime); 

this query giving me result like

hrs   count 00    1 01    1 05    1 12    1 15    2 

perform grouped join first collection enumerable.range(0, 24) , second collection foundrows.asenumerable().

example:

var input = new list<timespan> {     new timespan(15, 45, 00),     new timespan(15, 30, 54),     new timespan(00, 12, 14),     new timespan(01, 13, 47),     new timespan(05, 48, 23),     new timespan(12, 00, 47), };  var query = hour in enumerable.range(0, 24)             join item in input on hour equals item.hours g             select new             {                 calltime = hour,                 callcount = g.count(),             };  foreach (var x in query) {     console.writeline("{0:00} {1}", x.calltime, x.callcount); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -