title: Entity Framework, unable to create a constant value of type 'XX'. Only primitive types or enumeration types are supported in this context
body: <p>I have a method that returns viewmodel as defined below:</p>
  
  <pre><code>if (studentId != null)
  {
      var eduRec = (_context.EducationalRecords.Where(x =&gt; x.StudentId == studentId)).ToList();
      var guarnator = (_context.NextOfKinGuarantors.Where(x =&gt; x.StudentId == studentId)).ToList();
  
      model = (from stud in _context.Students
               join lga in _context.LocalGovts
                   on stud.LocalGovtId equals lga.LocalGovtId
               join st in _context.States
                   on lga.StateId equals st.StateId
               join acada in _context.AcademicRecords
                   on stud.StudentId equals acada.StudentId
               join dept in _context.Departments
                   on acada.DepartmentId equals dept.DepartmentId
               join faculty in _context.Falculties
                   on dept.FalcultyId equals faculty.FalcultyId
               join prg in _context.Programmes
                   on acada.ProgrammeId equals prg.ProgrammeId
               join lvl in _context.Levels
                   on acada.LevelId equals lvl.LevelId
               where acada.IsCurrentRecord == true &amp;&amp; stud.StudentId == studentId
               select new StudentProfileViewModel()
               {
                   ContactAddress = stud.ContactAddress,
                   Department = dept.Name,
                   Disability = stud.Disability,
                   Othernames = stud.Othernames,
                   FirstName = stud.FirstName,
                   Surname = stud.Surname,
                   Programme = prg.Name,
                   RegistrationNumber = stud.RegistrationNumber,
                   Dob = stud.Dob,
                   EducationalRecords = eduRec,
                   Email = stud.Email,
                   Faculty = faculty.Name,
                   Gender = stud.Gender,
                   HomeAddress = stud.HomeAddress,
                   Level = lvl.Name,
                   LocalGoverment = lga.Name,
                   MaritalStatus = stud.MaritalStatus,
                   Phone = stud.Phone,
                   Religion = stud.Religion,
                   StateName = st.Name,
                   NextOfKinGuarantors = guarnator
               }).FirstOrDefault();
  }
  </code></pre>
  
  <p>When I run the application I got this error message:</p>
  
  <blockquote>
    <p>Unable to create a constant value of type 'Portal.Models.EducationalRecord'. Only primitive types or enumeration types are supported in this context</p>
  </blockquote>
  
  <p>The definition of <code>EducationalRecords</code> is a list.</p>