2
如果我有這3類:LINQ - 分組和聚集
class Student { int id; string name; }
class Course { int id; string name; }
class Enrolment { int studentId; int courseId; DateTime enrolmentDate; }
然後使用此:
IEnumerable<Course> FindCoursesForStudent(Student student)
{
return from enrolment in Enrolments
where enrolment.studentId == student.id
join course in Courses
on enrolment.courseId equals course.id
select course;
}
我可以列出所有學生被錄取的課程。
但是,如果一個學生不止一次註冊了一門課程,我將如何顯示每門課程的最新註冊?
我假設我需要按課程進行分組,並過濾enrolmentDate = Max(enrolmentDate)或類似的地方?
(如果這看起來很熟悉,那是因爲這是一個後續從我previous LINQ question。)