Listコレクションは、あるフィールドに基づいて再集計される(groupby)
foreach (var iorder in iOrderList)
{
var tempIOrderDetailList = iOrderDetailList.Where(v => v.prId == iorder.prId).ToList();// iOrderDetailList
var ix_GoodsIds = (from i in tempIOrderDetailList
group i by i.donvvGoodsId into d
where d.Count() > 1
select d.FirstOrDefault().donvvGoodsId).ToList();// GoodsId
var tempOrderDetailList = (from i in tempIOrderDetailList
group i by i.donvvGoodsId into d
where d.Count() > 1
select new IOrderDetails()
{
Id=d.FirstOrDefault().Id,
prId = d.FirstOrDefault().prId,
prDetailId = d.FirstOrDefault().prDetailId,
commodityId = d.FirstOrDefault().commodityId,
skuId = d.FirstOrDefault().skuId,
BuyAmt = d.Sum(p => p.BuyAmt),
skuOrginPrice = d.FirstOrDefault().skuOrginPrice,
totelAmt = d.Sum(p => p.totelAmt),
status = d.FirstOrDefault().status,
erpId = d.FirstOrDefault().erpId,
donvvGoodsId = d.FirstOrDefault().donvvGoodsId,
SgccErpOrderDetailId=d.FirstOrDefault().SgccErpOrderDetailId,
ExpectedArrivalTime=d.FirstOrDefault().ExpectedArrivalTime
}).ToList();//
var tempOrderDetails = new List();
foreach (var ix_GodosId in ix_GoodsIds)
{
foreach (var iOrderDetail in tempIOrderDetailList)
{
if (iOrderDetail.donvvGoodsId == ix_GodosId)
{
tempOrderDetails.Add(iOrderDetail);
}
}
}
iOrderDetailList.RemoveAll(i => tempOrderDetails.Contains(i));// ( )
iOrderDetailList.AddRange(tempOrderDetailList);//
}