LINQ中基于组的字段串联 [英] Field concatenation based on group in LINQ

查看:29
本文介绍了LINQ中基于组的字段串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用LINQ根据Userid和date字段的分组连接一个time字段.我正在使用VS2010 C#(WPF).

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

我有一个以下格式的收藏集.

i have a collection in below format.

并希望得到类似

推荐答案

您要GroupBy用户ID,日期和大概的部门名称:

You want to GroupBy the UserId, Date and presumably 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)) });

应选择第一个UserIdDateDeptname.然后将日志时间结合在一起.尚未检查,但似乎应该可以.

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

这篇关于LINQ中基于组的字段串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆