Linq Group By

 var r = from l in Model.BankStatement_ItemSouce
                   where(l.STATUS==8)
                   group l by l.DOCUMENT_NO into g
                   select new { DOCUMENT_NO = g.Key,STATUS=g.Key, AMOUNT_RECEIVABLE =g.Where(t=>t.STATUS==8).Average(t => t.AMOUNT_RECEIVABLE), PRIJECT_VALUE=g.Sum(t=>t.PRIJECT_VALUE),ARREARS=g.Average(t=>t.ARREARS)};

           foreach (var item in r)
           {
               Model.AmountCount = item.AMOUNT_RECEIVABLE + Model.AmountCount;//应收总金额
               Model.ForegiftCount = item.PRIJECT_VALUE + Model.ForegiftCount;//实收总金额
               Model.ArrearsCount = item.ARREARS + Model.ArrearsCount;        //欠款总金额
           }

PS:开始要把AmountCount,ForegiftCount,ArrearsCount初始化为0.decimal类型。

 

posted @ 2015-05-21 14:45  歌·颂  阅读(337)  评论(0编辑  收藏  举报