我有一个数据表,其中的数据是这样的,其中一个功能可以有多个Storyid和不同的人分配给它。第一个图像的第一行featureid是26450而不是26540)我的错误
答案 0 :(得分:2)
让myTable
成为您当前的表格,然后您可以尝试使用以下代码来获得您正在寻找的结果:
var result = myTable.AsEnumerable().GroupBy(x=> x["Featureid"])
.Select(item => new
{
Feature = item.Key,
AssignedTo = string.Join(",", item.Select(a=>a["AssignedTo"])),
Stories = string.Join(",", item.Select(s=>s["storyid"])),
CompletedHrs= item.Sum(y=>y["CompletedHrs"]))
});
答案 1 :(得分:0)
让您的表名称为 FeatureAssigned
,然后您可以尝试以下代码。它将为您提供预期的输出
var result = db.FeatureAssigned
// If you have a filter add the .Where() here ...
.GroupBy(e => e.Featureid)
.ToList()
// Because the ToList(), this select projection is not done in the DB
.Select(eg => new
{
Feature= eg.Key,
AssignedTo = string.Join(",", eg.Select(b=>b.AssignedTo )),
Stories = string.Join(",", eg.Select(c=>c.storyid)),
CompletedHrs= eg.Sum(z=>z.CompletedHrs)
});