I have a nice linq query currently giving me exactly what I need, in this case a list of list<> objects grouped by date, however I need to also group by an ID field and was wondering how I would change the syntax to group by another field. I have tried multiple ways but can't seem to work it out so it still returns me a list of list<> objects grouped by entrydate AND ID fields.
Here is the code currently
var grouped = sales.SalesList.Where(s => !s.Ignore).GroupBy(s => s.EntryDate).Select(grp => grp.ToList()).ToList();
foreach (List<Sale> saleslist in grouped)
{
}
Thanks in advance.
A good way to do this is to group the multiples via an anonymous type:
var grouped = list.GroupBy(x => new { x.a, x.b, x.c });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With