I’m trying to do something similar to a SQL group by clause, but have no idea how to use LINQ.
As an example, let’s say my datatable dt1 has 10 fields, 1 of which is a datetime field. I want to select all 10 fields, including only the max(datetime) grouped by field1, field2, and field3
So if field1, field2, and field3 have duplicate items in the table, it will only keep the one with the maximum datetime field.
It would be simple in SQL, but no idea how to do this with LINQ - any help?
BONUS - I have scenarios within the same workflow where additional group by fields are needed (e.g. 5 group by instead of 3), dependent on the values in field1 and field2. Is it best to do this in 2 separate queries, or to combine it all at once?