我有以下的LINQ查詢,但我想修改它,我想通過staffId分組,並只選擇那些ObservationDate是每個staffId最大值的記錄。在單個查詢中LINQ查詢GroupBy和Max
from ob in db.TDTObservations.OfType<TDTSpeedObservation>()
select new
{
Id = ob.ID,
AcademicYearId = ob.Teachers.FirstOrDefault().Classes.FirstOrDefault().AcademicYearID,
observationDate = ob.ObservationDate,
schoolId = ob.Teachers.FirstOrDefault().Classes.FirstOrDefault().SchoolID,
staffId=ob.Teachers.FirstOrDefault().ID
};
見http://stackoverflow.com/questions/4775125/linq-query-with-grouping-and-ranking – Tassadaque 2013-03-21 11:06:39