Peter M Peter M - 3 years ago 111 Question Linq Agg Function for Class

I have a basic structure, in a list of:

Private Structure strcManagement
Dim Region as string
Dim Boss as string
Dim Employee as string
end Structure

Dim l as new list(of strcManagement)

Sample data looks like this:

l.add(new structure with {.Region = "Boston",.Boss="Joe Blow",Employee="Dan"})
l.add(new structure with {.Region = "Boston",.Boss="Joe Blow",Employee="Steve"})
l.add(new structure with {.Region = "Boston",.Boss="Joe Blow",Employee="Peter"})
l.add(new structure with {.Region = "CT",.Boss="Sam B",Employee="Brian"})

and I want to use linq to agg the data together where Region & Boss are grouped and the derived string is made on employee:

Boston,Joe Blow, [Dan,Steve,Peter]
CT, Sam B, [Brian]

I have seen examples with list(of string) but none with multiple grouped values. Any help would be appreciated.

Answer Source

Using LINQ Query Comprehension,

Dim ans = From m In l
          Group m By m.Region, m.Boss Into Group
          Select Region, Boss, Employees = String.Join(",", (From e In Group Select e.Employee))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download