我正在尝试组合这些值,如果有多个所有者ID,它会将行值添加到一起。
使用图像Given,如果我的查询已经运行,我最终会以
结束到目前为止我尝试了什么
from Person in TargetGroups
group Person by Person.PersonId into g
select new {g.PersonId, g.Value}
答案 0 :(得分:2)
您只需要连接Car
列的值,如下所示:
TargetGroups
.GroupBy(x => x.PersonId)
.Select(x => new { PersonId = x.Key, Cars = string.Join(",", x.Select(a => a.Car)) });
查询语法:
from Person in TargetGroups
group Person by Person.PersonId into g
select new { PersonId = g.Key, Cars = string.Join(",", g.Select(x => x.Car)) }