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
Post a Comment