title: How to add multiple records in List along with other model in view-model Linq - ASP.NET-MVC5
body: <p>I am working on ASP.NET-MVC5 applications. I need to pass data model from multiple classes from controller to view so I decided it use ViewModel and use linq to assign values to the view model accordingly. Now I my model, Student can have multiple emergency contact so I am using List but getting error on this part in LINQ query. </p>
  
  <p><img src="https://i.stack.imgur.com/VJ6Nu.png" alt="enter image description here"></p>
  
  <h2>ViewModel</h2>
  
  <pre><code>public class StudentDetailedProfileViewModel
  {
      public StudentDetailedProfileViewModel() { }
  
      public Student _studentModel { get; set; }
      public Course _courseModel { get; set; }
      public School _schoolModel { get; set; }
      public Campus _campusModel { get; set; }
      public ContactDetail _contactDetailModel { get; set; }
      public List&lt;EmergencyContact&gt; _emergencyContactModel { get; set; }
  
  }
  </code></pre>
  
  <h2>Function that need to return strongly typed binded data</h2>
  
  <pre><code> public StudentCourseSchoolAndCampusViewModel GetCourseByStudentID(int _studentID)
      {
          try
          {
              using (var _uow = new StudentProfile_UnitOfWork())
              {
                  var _record = (from _course in _uow.Course_Repository.GetAll()
                                join _school in _uow.School_Repository.GetAll() on _course.SchoolID equals _school.SchoolID
                                join _campus in _uow.Campus_Repository.GetAll() on _course.CampusID equals _campus.CampusID
                                where _course.StudentID == _studentID
                                select new StudentCourseSchoolAndCampusViewModel  {_courseModel= _course, _schoolModel = _school, _campusModel = _campus }).FirstOrDefault();
  
                  return _record;
              }
          }
          catch { return null; }
      }
  </code></pre>