Dane O'Connor Dane O'Connor - 1 year ago 136
C# Question

GroupBy with linq method syntax (not query syntax)

How would the following query look if I was using the extension method syntax?

var query = from c in checks
group c by string.Format("{0} - {1}", c.CustomerId, c.CustomerName)
into customerGroups
select new { Customer = customerGroups.Key, Payments = customerGroups }

Answer Source

It would look like this:

var query = checks
    .GroupBy(c => string.Format("{0} - {1}", c.CustomerId, c.CustomerName))
    .Select (g => new { Customer = g.Key, Payments = g });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download