C# LINQ GroupBy Max DateTime

Date: 2019-05-31
var measurementRepository = new MeasurementRepository();

            var lastMeasurementsWithHeaderTask = measurementRepository.AsQueryable()
                .Include(m => m.MeasurementHeader)
                .Where(m => m.SensorDateTime >= fromTime)
                .GroupBy(m => m.SensorId)
                .Select(m => m.FirstOrDefault(x => x.SensorId == m.Key && x.SensorDateTime == m.Max(y => y.SensorDateTime)))
                .ToListAsync();
21980cookie-checkC# LINQ GroupBy Max DateTime