我正在尝试创建一个查询,该查询返回与一个人的 id 关联的记录。
我试过这个:
viewModel.Students = db.Students.Where(sd => sd.StudentID==9);
但我不知道如何将它投射到我的身上,InstructorIndexData()
或者我是否应该那样做。如何更改此代码块以仅返回学生id==9
?
var viewModel2 = new InstructorIndexData();
viewModel.Courses = viewModel.Instructors.Where(
i => i.InstructorID == 2).Single().Courses
viewModel.Enrollments = viewModel.Courses.Where(
x => x.CourseID == 600).Single().Enrollments;
viewModel2.Students = db.Students.Where(sd => sd.StudentID==9);
return View(viewModel);
讲师索引数据:
public class InstructorIndexData
{
public IEnumerable<Instructor> Instructors { get; set; }
public IEnumerable<Course> Courses { get; set; }
public IEnumerable<Enrollment> Enrollments { get; set; }
public IEnumerable<Student> Students { get; set; }
public IEnumerable<Assignment> Assignments { get; set; }
}