Field concatenation based on group in LINQ

后端 未结 1 1060
你的背包
你的背包 2021-01-01 17:36

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.

相关标签:
1条回答
  • 2021-01-01 17:54

    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)) });
    

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

    0 讨论(0)
提交回复
热议问题