接触LINQ不久,写的可能不规范,但我要的分组统计功能实现了
贴出来供大家参考,如有高手还请指教,
private List<OutBoundDetailExtend> _outBoundDetailExtendList;
//赋值过程略
…………
var tmpList = from L in _outBoundDetailExtendList
group L by new { L.LocationId, L.PalletCode, L.SkuCode, L.Color, L.Size }
into S
select new OutBoundDetailExtend
{
AmountReceivable =
S.Select(O => O.AmountReceivable).First(),
BillId = S.Select(O => O.BillId).First(),
Quantity = S.Sum(O => O.Quantity),
…… //实体赋值过程略
//赋值过程略
…………
var tmpList = from L in _outBoundDetailExtendList
group L by new { L.LocationId, L.PalletCode, L.SkuCode, L.Color, L.Size }
into S
select new OutBoundDetailExtend
{
AmountReceivable =
S.Select(O => O.AmountReceivable).First(),
BillId = S.Select(O => O.BillId).First(),
Quantity = S.Sum(O => O.Quantity),
…… //实体赋值过程略
SkuCode = S.Key.SkuCode,
UnitPrice = S.Select(O => O.UnitPrice).First()
};
_outBoundDetailExtendList = tmpList.ToList();
UnitPrice = S.Select(O => O.UnitPrice).First()
};
_outBoundDetailExtendList = tmpList.ToList();