使用Entity Framework在多个数据库表的View中显示数据

时间:2018-07-07 10:46:59

标签: asp.net-mvc entity-framework-6

public ActionResult Studentdshboard()
{
    using (ApplicationDbContext context = new ApplicationDbContext())
    {
        var currentUserId = User.Identity.GetUserId();

        List<SelectListItem> list = new List<SelectListItem>();

        var StdInfo = (from r in context.Users
                       where r.Id == currentUserId
                       join s in context.Students on r.Id equals s.Id
                       join d in context.Departments on s.DepartmentId equals d.Id
                       join c in context.Classes on s.ClassId equals c.Id
                       join sec in context.Sections on s.SectionId equals sec.Id
                       select new
                           {
                               r.Name,
                               d.DepartmentName,
                               c.ClassName,
                               sec.SectionName
                           });

        return View(StdInfo.ToList());
    }
}

这是我的UsersDashboardController动作;如何在视图中显示上方列表

0 个答案:

没有答案