title: How can I change this block of code to return only records associated with a specific ID.?
body: <p>I’m trying to create a query that returns records associated with one person’s id. </p>
  
  <p>I’ve tried this:              </p>
  
  <pre><code>viewModel.Students = db.Students.Where(sd =&gt; sd.StudentID==9);
  </code></pre>
  
  <p>but I don’t know how to cast it to my <code>InstructorIndexData()</code> or whether I even should do it that way.  How can I change this block of code to return only student with <code>id==9</code>?</p>
  
  <pre><code>var viewModel2 = new InstructorIndexData();
  viewModel.Courses = viewModel.Instructors.Where(
      i =&gt; i.InstructorID == 2).Single().Courses               
  
  viewModel.Enrollments = viewModel.Courses.Where(
      x =&gt; x.CourseID == 600).Single().Enrollments;
  
  viewModel2.Students = db.Students.Where(sd =&gt; sd.StudentID==9);
  return View(viewModel);
  </code></pre>
  
  <p><strong>Instructor Index Data:</strong></p>
  
  <pre><code>public class InstructorIndexData
  {
      public IEnumerable&lt;Instructor&gt; Instructors { get; set; }
      public IEnumerable&lt;Course&gt; Courses { get; set; }
      public IEnumerable&lt;Enrollment&gt; Enrollments { get; set; }
      public IEnumerable&lt;Student&gt; Students { get; set; }
      public IEnumerable&lt;Assignment&gt; Assignments { get; set; }
  }
  </code></pre>