• LINQ 数据分组、统计实例


    接触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),
                              …… 
    //实体赋值过程略                                           
                              SkuCode = S.Key.SkuCode,   
                                               UnitPrice = S.Select(O => O.UnitPrice).First()
                                             };
                _outBoundDetailExtendList 
    = tmpList.ToList();   
  • 相关阅读:
    POJ 2976 Dropping tests
    【学习笔记-中国剩余定理】POJ1006 Biorhythms
    2017.10.6北京清北综合强化班DAY6
    P1607 [USACO09FEB]庙会班车Fair Shuttle
    2017.10.5北京清北综合强化班DAY5
    洛谷 P1379 八数码难题
    A. 拼音魔法
    A
    K
    A
  • 原文地址:https://www.cnblogs.com/pato/p/1970971.html
Copyright © 2020-2023  润新知