开发者

Merge non-grouping elements in column using LINQ

Is it possible to group rows with columns and have the remaining data merged in another column ?

Here's an image to better understand the question and see what I want to achieve:

The wanted result http://img693.imageshack.us/img693/9227/linqgrou开发者_StackOverflowpingquestion.gif

You can see the grouping by IdPlace, IdInternship and the new column IdUsers made with details, or composition of user ids.

I don't care if I cannot work anymore with data in new column, it's for display.


You're looking for something like:

var result = 
  collection.GroupBy(x => new { x.IdPlace, x.IdInternship })
    .Select(x => new { x.Key.IdPlace, x.Key.IdInternship,
           IdUsers = String.Join(", ", 
                        x.Select(c => c.IdUser.ToString()).ToArray()) });

(.ToArray() is unnecessary in .NET 4.0)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜