Total sum with Line

Asked

Viewed 35 times

1

I have no idea how to get the Total value = 755.00 of that 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:

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)
         };

1 answer

1


Your question doesn’t have many details, but if you’re wanting to show a grid as 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 off the raw tatal, you’d have to ride it with a UI, for this just create a variable with the value.

var TotalBruto = _total.Sum(t => t.ValorTotal);
  • perfect! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.