public IActionResult StudentGradesByCourseReport() { ViewData["Title"] = "Student Grades Report By Course"; var courses = _repo.ReadAllCourses(); var studentGrades = _repo.ReadAllStudentGrades(); /* * var query = courses * .GroupJoin( * studentGrades, * c => new { Code = c.Code, Number = c.Number }, * sg => new { Code = sg.CourseCode, Number = sg.CourseNumber }, * (c, grades) => new { Course = c, StudentGrades = grades }) * .Select(csg => new CourseGroupVM * { * CourseCodeNumber = csg.Course.Code + csg.Course.Number, * StudentGrades = csg.StudentGrades * }); * */ var query = from c in courses join sg in studentGrades on new { Code = c.Code, Number = c.Number } equals new { Code = sg.CourseCode, Number = sg.CourseNumber } into StudentCourseGrades select new CourseGroupVM { CourseCodeNumber = c.Code + c.Number, StudentGrades = StudentCourseGrades }; var model = query.ToList(); return(View(model)); }