I need to take a collection and group it via Linq but all the examples I\'ve seen fail in some manner or other with some syntax difference that I can\'t quite lick.
My c
Here is the linq code I would write (in c# - sorry I couldn't complete it in VB)
var res = a.GroupBy(i=>i.EmailAddress )
.Select(g=> new KeyValuePair(
g.Key,
string.Join(",", g.Select(x=> x.AlertType ).ToArray())
));
This will give you the output you want in a collection of KeyValuePair
in order to group them by both LoadNumber and EmailAddress this would be the c# code:
var res = alerts
.GroupBy(a => new { L = a.LoanNumber, E = a.EmailAddress })
.Select(a => new
{
LoadNumber = a.Key.L,
EmailAddress = a.Key.E,
Types = string.Join(", ", a.Select(x => x.AlertType).ToArray())
}).ToList();
where result is a List of a Complext type {LoadNumber, EmailAddress, Types}