【问题标题】:Where is the mistake? Group by, join , select .net错误在哪里?分组、加入、选择 .net
【发布时间】:2017-06-29 15:48:39
【问题描述】:

我不知道错误在哪里,为什么它说不包含 ImporteSolicitado、interesesDemora 和 importeReintegro 的定义,而它们是 c 的列和 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) });

【问题讨论】:

    标签: c# linq join linq-group


    【解决方案1】:

    您的组元素包含两个属性 cd。所以你需要参考 此属性为

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

    【讨论】:

    • 嗨,我试过这个解决方案,但是当他们执行这个时,var没有值,有这个错误静态成员=错误CS0119:'ArgumentException'是一种类型,在给定的上下文中无效.另一点是我也想展示 expediente.codigo。谢谢你
    【解决方案2】:

    在发布查询时很难做到这一点。我尽力了,但可能并不完全正确。

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

    【讨论】:

    • 嗨,我试试你的答案,但不完全正确,因为我没有显示 expediente.codigo,所以我看不到 group by 的结果是否正确,我认为是的,但是并不完全完整。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 2017-04-04
    • 2013-08-05
    相关资源
    最近更新 更多