wpf LINQ中基于组的字段连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18203169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:25:44  来源:igfitidea点击:

Field concatenation based on group in LINQ

c#wpflinq

提问by J R B

I want concate a times field based on grouping of Userid and dates field using LINQ . i am using VS2010 C#(WPF).

我想使用 LINQ 连接基于 Userid 和日期字段分组的时间字段。我正在使用 VS2010 C#(WPF)。

i have a collection in below format.

我有以下格式的集合。

enter image description here

在此处输入图片说明

and want result like

并希望结果像

enter image description here

在此处输入图片说明

回答by CodingIntrigue

You want to GroupBythe UserId, Date and presumably Deptname:

您想要GroupByUserId、Date 和大概的 Deptname:

_context.Log.GroupBy(l => new { l.UserId, l.dates.Date, l.Deptname })
            .Select(g => new { g.Key.UserId, g.Key.Date, g.Key.Deptname, Log = string.Join(",", g.Select(i => i.times)) });

Should select the first UserId, Dateand Deptname. Then join the log times together. Haven't checked this but seems like it should work.

应该选择第一个UserIdDateDeptname。然后将日志时间连接在一起。没有检查过这个,但似乎它应该工作。