通过linq查询一起添加字符串

编程入门 行业动态 更新时间:2024-10-11 17:20:12
本文介绍了通过linq查询一起添加字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试合并这些值,如果有多个所有者ID,则会将这些行值加在一起.

I'm trying to combine the values, if multiple owner id it'll add the line values together.

i.snag.gy/fOWWQ.jpg

有了给定的图像,如果我的查询运行了,我最终会得到

With the image Given, if my query is ran I would end up with

i.snag.gy/qO1DO.jpg

到目前为止我已经尝试过的

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查询一起添加字符串

本文发布于:2023-11-22 00:23:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!