c# 4.0 - aggregate function on linq to sql result -


i need calculate average grade dealers.

my results retrieved using linq below:

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(); 

now, want avg = (sum of totalpoints)/gradedata.count

the problem unable sum of totalpoints gradedata.

can me, how achieve without using foreach?

thanks in advance

you can use "sum" aggregate function.

int sum = gradedata.sum(o => o.totalpoints);


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -