lambda group by 的用法
Posted 一发寒冰箭
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 });//根据FShirtOrdNO,FKeyWorkCenterE_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 的用法的主要内容,如果未能解决你的问题,请参考以下文章