c# - Group By from DataTable using linq -



c# - Group By from DataTable using linq -

hi having result set follows

id name cost 1 xyz 10 2 abc 10 1 abc 20

i perform grouping should give me

id name cost 1 xyz 10 abc 20 2 abc 10

i tried solution form links couldn't datatable linq query grouping column can 1 help me

unless want alter original objects, you're going have project new collection , remove repeated id values. like:

var query = data.groupby(d => d.id) .orderby(g => g.key) .selectmany(g => (new[] {new { g.first().id, g.first().name, g.first().price}}) .concat(g.skip(1).select(i => new { id = (string)null, i.name, i.price})));

essentially:

group id take values of first item in each group take values except id other items in group

c# linq datatable

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? -