c# - linq group by and count -


select  uc.adminid, count(*) users uc join usersmessage ucm on uc.admincallid = ucm.admincallid uc.calldate between '2016-08-01' , '2016-09-01' , ucm.type = 4 group uc.adminid order count(*) 

and here i've tried:

 public static dictionary<int, int> returnsomething(int month)         {              dictionary<int, int> dict = new dictionary<int, int>();             using (dataaccessadapter adapter = new dataaccessadapter())             {                 linqmetadata meta = new linqmetadata(adapter);                 dict = (from uc in meta.users                         join ucm in meta.meta.usersmessage on uc.admincallid equals ucm.admincallid                          ucm.type == 4 && uc.calldate.month == month                         group uc uc.adminid g                         select new { /* ???? adminid = g. */ }).todictionary(x => new dictionary<int, int>(/* ????? x, x.name*/));             }              return dict;         } 

how can achieve need?

the key of dictionary key of groupby , value count(), need:

// ... .todictionary(g => g.key, g => g.count()); // key admincallid , value how id occured 

since you've asked how order decending:

you building dictionary has no order(well, should read: non-deterministic). ordering unnecessary. why it's unordered? read this

but if create else , wanted know how order count desc use this:

from uc in meta.users join ucm in meta.meta.usersmessage on uc.admincallid equals ucm.admincallid  ucm.type == 4 && uc.calldate.month == month group uc uc.adminid g orderby g.count() descending select new { adminid = g.key, count = g.count() }) 

Comments