对序列进行分类汇总,汇总后产生的序列的key就是按照某个字段汇总的项 。
groupby select Viewmodel三者常一起使用,用于统计。
groupby 方法语法常与select 子句形成数据 viewModel 的 数据投影。
public ActionResult Index() { var context = new SiteDataContext(); var notifications = context.Notifications .GroupBy(n => n.NotificationType) .Select(g => new NotificationViewModel { Count = g.Count(), NotificationType = g.Key.ToString(), BadgeClass = NotificationType.Email == g.Key ? "success" : "info" }); ViewBag.Notifications = notifications; return View(); }

相关文章:

  • 2022-01-08
  • 2021-12-24
  • 2022-12-23
  • 2021-05-16
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-10-01
  • 2022-12-23
相关资源
相似解决方案