Example #1
0
        public IActionResult StudentsCoursesWithA()
        {
            ViewData["Title"] = "Students and Courses with A";
            var students      = _repo.ReadAllStudents();
            var studentGrades = _repo.ReadAllStudentGrades();

            /*
             * var query = students
             *  .Join(
             *      studentGrades,
             *      s => s.ENumber,
             *      sg => sg.StudentENumber,
             *      (s, sg) => new { Student = s, StudentGrade = sg })
             *  .Where(sc => sc.StudentGrade.LetterGrade == "A")
             *  .Select(sc => new StudentCourseVM
             *  {
             *      LastName = sc.Student.LastName,
             *      CourseCode = sc.StudentGrade.CourseCode,
             *      CourseNumber = sc.StudentGrade.CourseNumber
             *  });
             */
            var query = from s in students
                        join sg in studentGrades on s.ENumber equals sg.StudentENumber
                        where sg.LetterGrade == "A"
                        select new StudentCourseVM
            {
                LastName     = sg.Student.LastName,
                CourseCode   = sg.CourseCode,
                CourseNumber = sg.CourseNumber
            };
            var model = query.ToList();

            return(View(model));
        }