lambda 表达式分组,分页与linq 分组查询语句

        // lambda 表达式 分组,并且分页
     ///
/// 获取所有组织机构数据(按价格名称分组) /// /// public string PriceStandardSelectAllGroupBy() { IList mPriceStandards = new List(); IList mGroupPriceStandards = new List(); int mTotal = 0; int mStart = 0; int mLimt = 0; if (Request.Params["id"] != null && !string.IsNullOrEmpty(Request.Params["id"].ToString())) { mPriceStandards.Add(PriceStandardSrv.GetById(Request.Params["id"].ToString())); mTotal = 1; } else { // 设置查询参数 var mConditions = new PriceStandard(); TryUpdateModel(mConditions); // 设置分页参数 mStart = int.Parse(Request.Params["start"]); mLimt = int.Parse(Request.Params["limit"]); mConditions.rowStart = mStart + 1; mConditions.rowEnd = mStart + mLimt; // 设置排序参数 if (!string.IsNullOrEmpty(Request.Params["sort"])) { mConditions.sorts = JsonConvert.DeserializeObject>(Request.Params["sort"]); } else { mConditions.sorts = new List() { new Sort() { property = "id", direction = "DESC" } }; } mPriceStandards = PriceStandardSrv.SelectAll(); mGroupPriceStandards = mPriceStandards .GroupBy(m => new { m.priceName }) .Select(g => new PriceStandard { priceName = g.Key.priceName, }).ToList(); mTotal = mGroupPriceStandards.Count(); mGroupPriceStandards = mGroupPriceStandards .Skip(mStart * mLimt) .Take(mLimt) .ToList(); } var output = JsonConvert.SerializeObject(mGroupPriceStandards, new IsoDateTimeConverter()); var returnStr = @"{ success: true, total: " + mTotal.ToString() + @", data: " + output + @"}"; return returnStr; } //linq 分组 IList mGroupPriceStandards = new List(); mGroupPriceStandards = (from m in mPriceStandards group m by new { m.priceName, m.salesTypeName } into g select new PriceStandard { priceName = g.Key.priceName, salesTypeName = g.Key.salesTypeName }).ToList();

 

转载于:https://www.cnblogs.com/xust/articles/2876786.html

你可能感兴趣的:(lambda 表达式分组,分页与linq 分组查询语句)