c# - GroupBy Issue in LINQ -



c# - GroupBy Issue in LINQ -

first sorry bad question title !

i have next query:

var q = t1 in userscores.where(c=>c.userid == 1) t2 in points.where(c => c.id == t1.id) t3 in couponspackages.where(c => c.id == t1.id).defaultifempty() grouping t2 new { t1.id, t1.value, t1.operand, t2.title, t2.rate, t3.scoreamount } g select new { g.key.title, score = (g.key.id < 3 ? (g.key.id == 1 ? g.key.value : g.key.scoreamount) : (g.key.operand == 1 ? g.key.rate * 1 : g.key.rate * -1)) };

the result like:

title score 10 50 b 30 c 60 c -30

but need this:

title score 60 b 30 c 30

each row = sum of same titles

how can reach result?

thanks !

you can utilize groupby:

q.groupby(x => x.title) .select(x => new { title = x.key, score = x.sum(s => s.score) });

c# sql asp.net linq

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -