动态Linq GroupBy选择无法正常工作 [英] Dynamic Linq GroupBy Select not working properly

查看:52
本文介绍了动态Linq GroupBy选择无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请指导,我能够使用Dynamic Group by,但是在选择非农业化字段时,出现以下错误

please guide, i am able to work with Dynamic Group by , but when selecting non agrigated fields , i get the following error

类型为"IGrouping`2"的属性或字段名称"不存在

No property or field 'name' exists in type 'IGrouping`2'

var result311 = (IQueryable)gle1.temptable.Where(a => a.IsAllowed == false && a.Code == "r01");

            var result = result311.GroupBy("new (name, FirstAmountOriginal, SecondAccounting)", "it")
                .Select("new (it.name,Sum(FirstAmountOriginal) as FirstAmountOriginalx, Sum(SecondAccounting) as SecondAccountingx)");

请指导

推荐答案

首先,您不应该按要汇总的字段分组,其次,分组会创建由字段组成的分组 Key 分组(在这种情况下为分组),因此您必须在此后解决此密钥:

Firstly, you should not group by the fields you want to aggregate and secondly, the grouping creates a grouping Key consisting of the fields you group by (in this case one), so you must address this key afterwards:

var result = result311.GroupBy("new(name)", "it")
    .Select(@"new (it.Key.name,
                   Sum(FirstAmountOriginal) as FirstAmountOriginalx, 
                   Sum(SecondAccounting) as SecondAccountingx)");

这篇关于动态Linq GroupBy选择无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆