Total sum with linq

1

I have no idea how to get Total Value = 755.00 from this select with Linq ?

| ID |Qtde  | Valor  | Total |
|  1 |  10  | 23.00  | 230.00|
|  1 |  15  | 10.00  | 150.00|
|  1 |  15  | 25.00  | 375.00| 
Total:                 755.00  

I imagine something like this:

var _total = from cta in ListConta()
         .Where(c => c.ContaID == pContaID)
         select new ContaView
         {
             ContaID = cta.ContaID ,
             Qtde = cta.Qtde,
             ValorTotal = cta.Pedido.ItensPedido.Sum(c => c.Valor)
         };
    
asked by anonymous 13.11.2016 / 22:49

1 answer

1

Your question does not have many details, but if you are looking for shows a grid like you showed at the beginning of the question would look like this;

var _total = from cta in ListConta()
         .Where(c => c.ContaID == pContaID)
         select new ContaView
         {
             ContaID = cta.ContaID ,
             Qtde = cta.Qtde,
             Valor = cta.Pedido.ItensPedido.Valor,
             ValorTotal = cta.Pedido.ItensPedido.Valor * cta.Qtde,
         };

If you need to show the raw tata, you would have to mount this with a UI, for this just create a varivavel with the value.

var TotalBruto = _total.Sum(t => t.ValorTotal);
    
14.11.2016 / 12:25