zoukankan      html  css  js  c++  java
  • Linq使用group by

    代码:

    DataTable dt = ClassWorkInfoBLL.GetStuWorkList(UserID, PageIndex, PageSize);
                    var data = from item in dt.AsEnumerable()
                               group item by new { t1 = item.Field<string>("CreateDate") } into m
                               select new
                               {
                                   CreateDate = Convert.ToDateTime(m.First().Field<string>("CreateDate")).ToString("yyyy年MM月dd日"),
                                   data = from c in m
                                          select new
                                          {
                                              ID = c.Field<int>("ID"),
                                              Name = c.Field<string>("Name"),
                                              IcoKey = c.Field<string>("IcoKey"),
                                              PubDate = Convert.ToDateTime(c.Field<DateTime>("PubDate")).ToString("yyyy-MM-dd HH:mm:ss"),
                                              EndDate = Convert.ToDateTime(c.Field<DateTime>("EndDate")).ToString("yyyy-MM-dd HH:mm:ss"),
                                              Description = c.Field<string>("Description"),
                                              IsDone = c.Field<object>("IsDone"),//类型是:Int64;可能因为是64位系统?
                                              ClassID = c.Field<int>("ClassID"),
                                              TypeID = c.Field<int>("TypeID"),//作业类型 照片=1,视频=2;
                                          }
                               };

    var res = query.GroupBy(x => new
    {
    x.Project,
    x.BYear,
    x.BMonth
    }).Select(x => new
    {
    x.Key.Project,
    x.Key.BYear,
    x.Key.BMonth,
    Amount = x.Sum(a => a.Amount)
    });

  • 相关阅读:
    Linux pmap 工具
    bzoj 1060 贪心
    bzoj 1076 状压DP
    bzoj 1150 贪心
    bzoj 1412 最小割 网络流
    bzoj 3212 线段树
    bzoj 1942 斜率优化DP
    bzoj 1876 高精
    bzoj 1880 最短路
    斜率优化DP讲解
  • 原文地址:https://www.cnblogs.com/xsj1989/p/8317410.html
Copyright © 2011-2022 走看看