C# linq group by multiple columns

Date: 2019-11-25
public async Task<IEnumerable<Measurement>> GetLastMeasurementForEachSensor()
{
	var groupedMaxDateTime = AsQueryable()
		.GroupBy(m => m.SensorId)
		.Select(m => new
		{
			SensorId = m.Key,
			SensorDateTime = m.Max(y => y.SensorDateTime)
		});
	var dmMeasurements = await AsQueryable()
		.Join(groupedMaxDateTime,
			(DmMeasurement a) => new { a.SensorId, a.SensorDateTime },
			b => new { b.SensorId, b.SensorDateTime },
			(a, b) => a
		)
		.Select(x => new DmMeasurement {
			SensorId = x.SensorId,
			ReceivedAt = x.ReceivedAt,
			ReceivedValue = x.ReceivedValue
		})
		.ToListAsync();
	return dmMeasurements.Select(x => x.ToDomain(true));
}
29330cookie-checkC# linq group by multiple columns