请指导,我可以使用Dynamic Group,但是当选择非灌溉字段时,我会收到以下错误
'IGrouping`2'
类型中不存在属性或字段'name'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)");
请指导
答案 0 :(得分:2)
首先,您不应按要聚合的字段进行分组;其次,分组会创建一个分组Key
,其中包含您分组的字段(在本例中为一个字段),因此您必须先处理此密钥:
var result = result311.GroupBy("new(name)", "it")
.Select(@"new (it.Key.name,
Sum(FirstAmountOriginal) as FirstAmountOriginalx,
Sum(SecondAccounting) as SecondAccountingx)");