码迷,mamicode.com
首页 > 其他好文 > 详细

lambda group by 的用法

时间:2017-01-23 18:30:45      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:style   div   color   ffffff   repo   count   clear   log   tin   

foreach (DynamicObject lstKSItem in lstKSItems)
            {
                var entity = lstKSItem["FEntity"] as DynamicObjectCollection;
                if (entity.Count == 0) continue;
                var groupKeys = entity.Select(p => new
                {
                    FShirtOrdNO = Convert.ToString(p["FShirtOrdNO"]),
                    FKeyWorkCenterE_Id =
                        Convert.ToString(p["FKeyWorkCenterE_Id"]) 
                }).GroupBy(p => new {p.FShirtOrdNO,p.FKeyWorkCenterE_Id });//根据FShirtOrdNOFKeyWorkCenterE_Id分组
                if (groupKeys.Count() > 1)
                {
                    foreach (var groupKey in groupKeys)
                    {
                        ;
                        var DataEntityCopy = OrmUtils.Clone(lstKSItem, lstKSItem.DynamicObjectType, true, true) as DynamicObject;
                        var DataEntityCopyObjs = DataEntityCopy["FEntity"] as DynamicObjectCollection;
                        DataEntityCopyObjs.Clear();
                        var groupByShirtOrdNOObjs = entity.Where(o => Convert.ToString(o["FShirtOrdNO"]) == groupKey.Key.FShirtOrdNO 
                            && Convert.ToString("FKeyWorkCenterE_Id")==groupKey.Key.FKeyWorkCenterE_Id).ToArray<DynamicObject>();//
                        int i = 0;
                        foreach (DynamicObject groupByShirtOrdNOObj in groupByShirtOrdNOObjs)
                        {
                            groupByShirtOrdNOObj["Seq"] = ++i;
                            DataEntityCopyObjs.Add(groupByShirtOrdNOObj);
                        }
                        decimal SumQty = (DataEntityCopy["FEntity"] as DynamicObjectCollection).Sum(o => Convert.ToDecimal(o["FReportQty"]));
                        DataEntityCopy["FSumQty"] = SumQty;
                        AddGroupItems.Add(DataEntityCopy);
                    }
                }
                else
                {
                    AddGroupItems.Add(lstKSItem);
                }

 

lambda group by 的用法

标签:style   div   color   ffffff   repo   count   clear   log   tin   

原文地址:http://www.cnblogs.com/liuyudong0825/p/6344450.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!