2

请指导,我可以使用 Dynamic Group by,但是在选择非聚合字段时,我收到以下错误

类型“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)");

请指导

4

1 回答 1

4

首先,您不应按要聚合的字段进行分组,其次,分组会创建一个Key由您分组的字段组成的分组(在本例中为一个),因此您必须在之后解决此键:

var result = result311.GroupBy("new(name)", "it")
    .Select(@"new (it.Key.name,
                   Sum(FirstAmountOriginal) as FirstAmountOriginalx, 
                   Sum(SecondAccounting) as SecondAccountingx)");
于 2013-04-16T15:19:59.997 回答