我有一张桌子,
**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
基于上面的场景,我希望返回所有列,但DISTINCT ROWS基于Columns - Matter No和Client No.,即我需要看到3行作为输出:
**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
我如何在LINQ中实现这一目标?
提前致谢
from x in table group x by new {x.MatterNo, x.ClientNo} into mygroup select mygroup.First();
或者如果您更喜欢这种语法
list.DistinctBy(x => new {x.MatterNo, x.ClientNo});
如果您没有处理列表,可以尝试
from DataRow drow in dtable.Rows group drow by new {MatterNo = drow["Matter No"], ClientNo = drow["Client No"]} into myGroup select myGroup.First();