zoukankan      html  css  js  c++  java
  • linq lambda 分组后排序

    1.lamdba分组排序
    foodBusinessDistrict.
                            GroupBy(x => new
                            {
                                x.CityLocationID,
                                x.CityLocationName,
                                x.BusinessDistrctID,
                                x.BusinessDistrctName
                            })
                            .Select(g=> new BusinessDistrictWithCountModel
                            {
                                CityLocationID = g.Key.CityLocationID,
                                CityLocationName = g.Key.CityLocationName,
                                BusinessDistrctID = g.Key.BusinessDistrctID,
                                BusinessDistrctName = g.Key.BusinessDistrctName,
                                ProductCount = g.Sum(a => a.ProductCount)
                            })
                            .OrderByDescending(x => x.ProductCount)
                            .ToList();


    2.group分组
    eg1.
    var id = (from p in (from ps in GPEcontext.hbl_product_stock
                        group ps by new {ps.ProductID}
                        into G
                        select new
                        {
                            Key = G.Key,
                            Count = G.Count()
                        })
                        orderby p.Count descending
                             select p.Key.ProductID.Value).FirstOrDefault();
    eg2.
    DataTable dt = (from x in dsResult.Tables[0].AsEnumerable()
                                    where DataTrans.CBoolean(x["IsChecked"]) == true
                                    group x by new

                                    {
                                        no = x.Field<string>("NO"),
                                        ptno = x.Field<string>("PTNO"),
                                        ver = x.Field<int>("VER"),
                                        kd = x.Field<string>("KD"),
                                        que_da = Convert.ToDateTime(x.Field<DateTime>("QUE_DA").ToString("yyyy/MM/dd"))

                                    } into g
                                    orderby g.Key.no,g.Key.ptno,g.Key.ver,g.Key.kd,g.Key.que_da
                                    select new
                                    {
                                        qty = g.Sum(x => Convert.ToInt32(x["QUE_QTY"])),
                                      stock=g.Sum(x=>Convert.ToInt32(x["STOCK"])),
                                      no=g.Key.no ,
                                      ptno=g.Key.ptno,
                                      ver=g.Key.ver,
                                      kd=g.Key.kd,
                                      que_da=g.Key.que_da
                                    }).ConvertDataTable();

  • 相关阅读:
    getline函数
    Java获取某年某月的第一天
    计划任务中使用NT AUTHORITYSYSTEM用户和普通管理员用户有什么差别
    Windows 7系统安装MySQL5.5.21图解
    C#高性能大容量SOCKET并发(十一):编写上传client
    Linux 终端訪问 FTP 及 上传下载 文件
    完毕port(CompletionPort)具体解释
    ping不通的几种可能原因
    Apple Swfit UI控件实现
    js中取session的值
  • 原文地址:https://www.cnblogs.com/ChineseMoonGod/p/5213892.html
Copyright © 2011-2022 走看看