Is it possible to obtain two independent results (sum) from a single query in LINQ?

0

I am modifying a program and I want to obtain two sums independently of the id and save them in independent variables one of another. It would also be useful to obtain a table resulting from a line with only the two columns added.

With this example table.

+----+--------+-----------------+
| id | sueldo | propiedades(m2) |
+----+--------+-----------------+
|  1 |   1000 |             400 |
|  2 |   1500 |             200 |
|  3 |   2000 |             300 |
+----+--------+-----------------+



 sueldototal, propiedadestotal = (from...where..select)

or

dim z = (....select sum(sueldo), sum(propiedades))

result (z):

+--------+-----------------+
| sueldo | propiedades(m2) |
+--------+-----------------+
|   4500 |             900 |
+--------+-----------------+

Thanks in advance.

    
asked by Ricard 22.08.2018 в 12:18
source

1 answer

1

You can use an anonymous class to have the data categorized in a new class. It would be something like this:

Dim resSuma = New With {Key
  .sueldo = dt1.AsEnumerable().Sum(Function(x) x.Field(Of Integer)("sueldo")), Key
  .propiedades = dt1.AsEnumerable().Sum(Function(x) x.Field(Of Integer)("propiedades"))
  }

To access the results, simply put resSuma.Sueldo and resSuma.propiedades .

    
answered by 22.08.2018 в 13:59