[Solved] How to convert linq query to non-query expression?


If you want to convert this to the method syntax version, you can do this step by step. I like to start at the end and work through to the beginning:

  1. select to Select defines the source:

    .Select(g => g.OrderByDescending(s => s.MeasureDate).FirstOrDefault());
    
  2. group is GroupBy:

    .GroupBy(s => s.SensorUnitId)
    .Select(g => g.OrderByDescending(s => s.MeasureDate).FirstOrDefault());
    
  3. from the source

    SensorObservationEntities.SensorsMeasures
    .GroupBy(s => s.SensorUnitId)
    .Select(g => g.OrderByDescending(s => s.MeasureDate).FirstOrDefault());
    

solved How to convert linq query to non-query expression?