我有一张这样的桌子
Id TagNo FromBay FromPanel FDevice FRef
1 1000 A B C1 1
2 1000 A B C1 2
3 1000 A B C1 R2
4 1000 A B C2 2
5 1000 A B C2 3
6 1000 A B C2 4
我想要这个
TagNo FromBay FromPanel FDevice FRef
1000 A B C1 1
2
R2
C2 2
3
4
这些值位于名为 cableDataTable 的数据表中
var rows = cableDataTable.AsEnumerable()
.Select(x => new
{
TagNo = x.Field<string>("TagNo"),
FromBay = x.Field<string>("FromBay"),
FromPanel = x.Field<string>("FromPanel"),
FDevice = x.Field<string>("FDevice"),
FRef = x.Field<string>("FRef")
});
var results = rows.GroupBy(row => new { row.FromBay, row.FromPanel, row.TagNo })
.OrderBy(g => g.Key.FromBay)
.ThenBy(g => g.Key.FromPanel)
.SelectMany(g => g.OrderBy(row => row.TagNo)
.Select((x, i) =>
new
{
TagNo = (i == 0) ? x.TagNo.ToString() : "",
FromBay = (i == 0) ? x.FromBay : "",
FromPanel = (i == 0) ? x.FromPanel : "",
FDevice = (i == 0) ? x.FDevice : "",
FRef = x.FRef,
})).ToList();
但我明白了
TagNo FromBay FromPanel FDevice FRef
1000 A B C1 1
2
R2
2
3
4
我在一个论坛中找到了可能,但我不知道 .Select((x, i) 能做什么,我怎样才能得到我需要的结果。我找不到问题