asp.net - find most occurrences in linq to sql c# -
i have below query gets name , totalpoints follows:
var gradedata = (from data in oangiectxt.prc_shopinstancecustomersdata(convert.toint32(this.shopinstanceid), 10000, false) .where(row => row.recievedpoints != "n/a") .groupby(row => new { row.name }) .select(g => new { totalpoints = g.sum(x => convert.todouble(x.recievedpoints) * (x.weightage.tostring() == "0.00" ? 1 : convert.todouble(x.weightage))), name = g.key.name }) select data).tolist();
i have data below:
totalpoints name 5 10 b 5 c 15 d 5 e
if observe above list 5 common.
i have fetch value "gradedata".
can me how that?
thanks in advance...
-- both solutions below working vote both.. thanku
var mostcommon = gradedata.groupby(x => x.totalpoints) .orderbydescending(g => g.count()) .select(g => g.key) .first();
Comments
Post a Comment