i have the following action method that calls a repository method:-
public ActionResult Details(int id)
{
Instructor i = repository.FindInstructor(i);
ViewBag.assessmentid = repository.FindassessmentID(id);
if (i == null)
return View("NotFound");
else
return View(i);}
but how i can define that i need to define an eager loading for the Position navigation property on the instructor entity (as the instructor might hold 0 or many positions), the FindInstructor(i) repository method look as the folloiwng:
public Question FindInstructor(int id)
{
return entities1.Instructors.FirstOrDefault(d => d.InstructorID == id); }
the intellisense will NOT allow me to write something like :-
return entities1.Instructors.Include(c => c.Position).FirstOrDefault(d => d.InstructorID == id); }
so what i am missing in my code???
The overload of the Include method which takes a property expression is an extension method in the
System.Data.Entitynamespace.Add this using to your file and it should work:
You can read more about how eager loading works: Loading Related Entities