I have a method that returns viewmodel as defined below:
if (studentId != null)
{
var eduRec = (_context.EducationalRecords.Where(x => x.StudentId == studentId)).ToList();
var guarnator = (_context.NextOfKinGuarantors.Where(x => 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 && 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();
}
When I run the application I got this error message:
Unable to create a constant value of type 'Portal.Models.EducationalRecord'. Only primitive types or enumeration types are supported in this context
The definition of EducationalRecords
is a list.