本文介绍了通过linq查询一起添加字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试合并这些值,如果有多个所有者ID,则会将这些行值加在一起.
I'm trying to combine the values, if multiple owner id it'll add the line values together.
有了给定的图像,如果我的查询运行了,我最终会得到
With the image Given, if my query is ran I would end up with
到目前为止我已经尝试过的
What I've tried so far
from Person in TargetGroups
group Person by Person.PersonId into g
select new {g.PersonId, g.Value}
推荐答案
您只需要将Car
列的值连接起来,就像这样:
You just need to concatenate values of Car
column like this:
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)) }
这篇关于通过linq查询一起添加字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!