Mark Tabor

Mark Tabor

  • 589
  • 2k
  • 456.9k

Linq Query Return zero rows how to make left join with linq

Sep 21 2020 2:44 AM
Hi i am facing a problem with my Linq query i have the following table
 
 
the issue is i am getting zero rows and when i inspect and bebug the query it says "Enumeration yielded no results"
 
below is my index method
  1. public ActionResult Index()  
  2. {  
  3. ViewBag.PopulateGrades = _IEducation.PopulateGrade();  
  4. ViewBag.PopulatePrograms = _IEducation.PopulatePrograms();  
  5. ViewBag.PopulateStudents = _IEducation.PopulateStudents();  
  6. ViewBag.PopulateCourses = _IEducation.PopulateCourses();  
  7. ViewBag.PopulateModules = _IEducation.PopulateModules();  
  8. ViewBag.PopulateYear = _IYear.PopulateYears();  
  9. var StudentVSCourses = db.StudentCoursesAssigned.ToList();  
  10. ViewBag.Block_Id = new SelectList(db.Blocks, "Id""Name");  
  11. ViewBag.Semester_Id = _ITeacherCoruses.PopulateSemsters();  
  12. using (DatabaseContext db = new DatabaseContext())  
  13. {  
  14. List<Student_Assigned_courses> Student_Assigned_courses = db.StudentCoursesAssigned.ToList();  
  15. List<Courses> courses = db.Courses.ToList();  
  16. List<Moduel> Module = db.Moduels.ToList();  
  17. List<Years> year = db.Years.ToList();  
  18. List<Semesters> semesters = db.Semesters.ToList();  
  19. List<Programs> Programs = db.Programs.ToList();  
  20. List<Student> students = db.Students.ToList();  
  21. List<Courses> curr = db.Courses.ToList();  
  22. List<Grade> grade = db.grades.ToList();  
  23. IEnumerable<Courses> h = db.Courses.ToList();  
  24. var employeeRecord = from e in Student_Assigned_courses  
  25. join d in students on e.Student_id equals d.Student_Id into table1  
  26. from d in table1.ToList()  
  27. join i in courses on e.Course_Id equals i.Course_Id into table2  
  28. from i in table2.ToList()  
  29. join m in Module on e.Module_Id equals m.Id into table3  
  30. from m in table3.ToList()  
  31. join y in year on e.Year_Id equals y.Id into table4  
  32. from y in table4.ToList()  
  33. join p in Programs on e.Program_Id equals p.Id into table5  
  34. from p in table5.ToList()  
  35. join g in grade on e.Grade equals g.Id into table6  
  36. from g in table6.ToList()  
  37. join s in semesters on e.Semster_Id equals s.Semester_Id into table7  
  38. from s in table7.ToList()  
  39. select new StudentCoursesViewModel  
  40. {  
  41. studentAssignedCourses = e,  
  42. courses = i,  
  43. programs = p,  
  44. //curses=curr,  
  45. curses = h,  
  46. semester = s,  
  47. studnets = d,  
  48. Year = y,  
  49. Modules = m,  
  50. grade = g,  
  51. };  
  52. return View(employeeRecord.ToList());  
  53. }  
if i comment the yellow highlighted section than it returns the rows , can someone tell me how to adjust the linq query so that it should return the rows no matter even if the semester is null.

Answers (11)