我有一些问题,不知道该怎么办,有人可以帮我吗?我有一张这样的桌子:
ID Name Produkt Comment aa bb
1 Mike AA YY x
1 Mike AA YY x
我想与 linq 分组,结果就像有 Mike 但就在一行中
1 Mike AA YY x x
我的代码:
var results = from t1 in table.AsEnumerable()
join tb2 in table2.AsEnumerable()
on t1.Field<string>("Name") equals tb2.Field<string>("Name") into prodGroup
from table4 in prodGroup.DefaultIfEmpty()
select new
{
ID = t1.Field<Int32?>("ID"),
Name = t1.Field<String>("Name"),
Produkt = t1.Field<String>("Produkt"),
Attribute = t1.Field<String>("Attribute"),
Comment = table4 != null ? table4.Field<String>("Comment") : null,
};
foreach (var r in results)
{
var productIndex = result.Columns.IndexOf(r.Attribute);
var vals = new List<object>() { r.ID, r.Name, r.Produkt, r.Comment };
for (int i = 4; i < result.Columns.Count; i++)
{
if (i == productIndex)
{
vals.Add(true);
}
else
{
vals.Add(false);
}
}
result.LoadDataRow(vals.ToArray(), true);
}