c# - LINQ - Return rows with all columns of a table based on multiple distinct columns -


i have table,

**matter no      client no    client name  invoice no  invoice date    invoice amt**  1111-0001          1111          abc            101       01/01/2013       100.00  1111-0001          1111          abc            102       02/01/2013       200.00 1111-0001          1111          abc            103       03/01/2013       300.00 1111-0001          1111          abc            104       04/01/2013       400.00 1111-0001          1112          def            105       05/01/2013       500.00 1111-0001          1113          ghi            106       06/01/2013       600.00 

based on above scenario, wish return columns distinct rows based on columns - matter no , client no. i.e. need see 3 rows output:

**matter no      client no    client name  invoice no  invoice date    invoice amt**  1111-0001          1111          abc            101       01/01/2013       100.00  1111-0001          1112          def            105       05/01/2013       500.00 1111-0001          1113          ghi            106       06/01/2013       600.00 

how can achieve in linq?

thanks in advance

from x in table group x new {x.matterno, x.clientno} mygroup select mygroup.first(); 

or if prefer syntax

list.distinctby(x => new {x.matterno, x.clientno}); 

if you're not dealing list can try

from datarow drow in dtable.rows group drow new {matterno = drow["matter no"], clientno = drow["client no"]} mygroup select mygroup.first(); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -