Consult related tables (Many to Many), grouping results C # Linq Asp.Net MVC

0

I have a problem.

I have 2 tables (Matricula and ValorAsistencia) that are related to an intermediate table "Assistances" (many to many).

What I want is to make a query that shows me data of the first table, and then a column with the sum of the data of the second related to that first table. Something like this:

In case it helps, the tables in question are the following:

The only thing I could do was:

   var agrupacion = from m in db.matricula
                         join a in db.asistencia on m.id equals a.matriculaid
                         group a by a.matriculaid into grupo                 
 join ma in db.matricula on grupo.firstordefault().matriculaid equals 
 a.matriculaid
                         select new
                         {
                         Id=grupo.firstordefault().matriculaid,
                         Matricula=ma.numero,
                         Faltas = grupo.count(), //Solo pude contar la cantidad de Asistencias y lo que necesito es sumar el valor de cada una.
    
asked by Rodrigo Ramirez 22.11.2018 в 23:42
source

0 answers