I have a query which returns a number of records.
For Example:
Click to See Records
I used the following query:
var sData = vehicle.GsmDeviceLogs
.Where(gs => gs.Speed > zeroSpeed && !gs.DigitalInputLevel1)
.OrderBy(gs => gs.DateTimeOfLog)
.ToList();
Now, I just want to fetch the first record for each date. i.e.
You gave the answer in your question itself, group by and then select the first. Technically you would translate it to linq as the following:
var sData = vehicle.GsmDeviceLogs
.Where(gs => gs.Speed > zeroSpeed && !gs.DigitalInputLevel1)
.OrderBy(gs => gs.DateTimeOfLog)
.GroupBy(gs => gs.DateTimeOfLog)
.Select(gs => gs.First())
.ToList();
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