linq - Getting Sum of Multiple Columns and summing up values for the same id from a list -


i have list returns.

grade col1 col2  col3  col4  t1   2    1      3     2  t2   2    5      1     5  t1   2    6      4     4  

first, need add values in each row corresponding grade , have

grade  sum(sum of 4 columns)      t1     8 t2     13 t1     16 

and result should like:

grade   total t1      8+16 = 24 t2       13 

i'm newbie linq., can suggest me approach using linq, returning result.??

thanks

following linq query group rows grade , produce sum of columns each grade:

var query = r in list             group r r.grade g             select new {                grade = g.key,                total = g.sum(x => x.col1 + x.col2 + x.col3 + x.col4)             }; 

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 -