Where is the mistake? Group by, join , select .net

63 Views Asked by At

I don´t know where is the mistake why it says that does not contain a defintion of ImporteSolicitado, interesesDemora and importeReintegro when they are colums of c and the last one of d

var importes = (from c in _context.ReintegroSolicitado
                join d in _context.ReintegroRecibido on c.Expediente.ID equals d.Expediente.ID 
                group new {c,d} by new { c.Expediente.Codigo} into cd
                select new { ImporteSolictadoFinal = cd.Sum(b => b.ImporteSolicitado + b.InteresesDemora), ImporteReintegroFinal = cd.Sum(e => e.ImporteReintegro) });
2

There are 2 best solutions below

1
jdweng On

This is very tough to get right with query posted. I did my best, but it is probably not exactly correct.

           var importes = (from c in _context.reintegroSolicitado
                            join d in _context.reintegroRecibido on c.expediente.ID equals d.expediente.ID
                            select new { reintegroSolicitado = c, reintegroRecibido = c})
                            .GroupBy(x => new { c = x.reintegroSolicitado , d = x.reintegroRecibido})
                            .Select(cd => new { ImporteSolictadoFinal = cd.Sum(b => b.reintegroSolicitado.ImporteSolicitado + b.reintegroSolicitado.InteresesDemora), ImporteReintegroFinal = cd.Sum(e => e.reintegroRecibido.ImporteReintegro) });

        }

    }
    public class Context
    {
        public List<ReintegroSolicitado> reintegroSolicitado { get; set; }
        public List<ReintegroSolicitado> reintegroRecibido { get; set; }
        public Expediente expediente { get; set; }
    }
    public class ReintegroSolicitado
    {
        public Expediente expediente { get; set; }
        public int ImporteSolicitado { get; set; }
        public int InteresesDemora { get; set; }
        public int ImporteReintegro { get; set; }
    }
    public class Expediente
    {
        public int ID { get; set; }
        public int Codigo { get; set; }
    }
1
parfilko On

your group element contains two property c and d. So you need refer to this property as

...
select new { 
    ImporteSolictadoFinal = cd.Sum(b => b.c.ImporteSolicitado + b.c.InteresesDemora),
    ImporteReintegroFinal = cd.Sum(e => e.d.ImporteReintegro) }
...