tags:

views:

55

answers:

1

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

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.

+2  A: 

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)

Mehrdad Afshari
+1 Very nice...
JonH