首页 > 代码库 > lambda group by 的用法

lambda group by 的用法

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 的用法