Linq - Grouping with sum calculation

前端 未结 2 428
生来不讨喜
生来不讨喜 2021-01-23 02:04

Linq noob here. How do I correct this?

                var result = (from row in rulestable.AsEnumerable()
                         let sup = row.Field

        
2条回答
  •  抹茶落季
    2021-01-23 02:20

    When I run this query I failed in visual studio. On More search found the following and worked well in my system.

    var result = (from row in rulestable.AsEnumerable() 
                 group row by new {sup= row.Field("Supplier"), 
                                  vat=row.Field("VatRate")} into grp = Group 
                 select new With 
                 {.Supplier = sup, 
                  .Amount = grp.Sum(r => r.Field("Amount")),
                  .Advance  = grp.Sum(r => r.Field("Advance")),
                  .Balance  = grp.Sum(r => r.Field("Balance")),
                  .VatRate  = vat
                  }
                 ).ToList();
    

提交回复
热议问题