// GET: Worker public ActionResult Index(int?id, int?organizationID) { var viewModel = new WorkerIndexData(); viewModel.Workers = db.Workers .Include(i => i.Office) .Include(i => i.Organizations.Select(c => c.Department)) .OrderBy(i => i.LastName); if (id != null) { ViewBag.WorkerID = id.Value; viewModel.Organizations = viewModel.Workers.Where( i => i.ID == id.Value).Single().Organizations; } if (organizationID != null) { ViewBag.CourseID = organizationID.Value; // Lazy loading //viewModel.Enrollments = viewModel.Courses.Where( // x => x.CourseID == courseID).Single().Enrollments; // Explicit loading var selectedCourse = viewModel.Organizations.Where(x => x.OrganizationID == organizationID).Single(); db.Entry(selectedCourse).Collection(x => x.Enrollments).Load(); foreach (Enrollment enrollment in selectedCourse.Enrollments) { db.Entry(enrollment).Reference(x => x.Client).Load(); } viewModel.Enrollments = selectedCourse.Enrollments; } return(View(viewModel)); }
public async Task OnGetAsync() { Tecnico = new WorkerIndexData(); Tecnico.Tecnicos = await _context.Tecnico // .Include(i => i.RoleAssignments) //.Include(i=> i.WorkerRole) .OrderBy(i => i.Name) .ToListAsync(); }