0
我想使用Linq执行嵌套GroupBy,我无法让它工作。我的代码如下:嵌套GroupBy使用Linq
var summaryFile = new RemittanceCenterFilesSummaryListModel
{
RemittanceFilesSummary = remittanceCenterSummaryListModel.RemittanceBatchSummaryRecord.GroupBy(x => new { x.FileId, x.SourceFileName })
.Select(x => new RemitanceCenterFileSummarizedModel
{
FileId = x.Key.FileId,
SourceFileName = x.Key.SourceFileName,
Batches = x.ToList().GroupBy(b => new { b => b.BatchCode })
.Select(c => new RemittanceCenterBatchSummarizedModel
{
FileId = x.Key.FileId,
SourceFileName = x.Key.SourceFileName,
BatchCode = c.Key,
BatchType = c.Key,
DetailRecordCountAdc = x.Count(y => y.BillingSystemCode == BillingSystemCode.Adc),
DetailRecordCountNotAdc = x.Count(y => y.BillingSystemCode == BillingSystemCode.Exceed),
AmountAdc = x.Where(y => y.BillingSystemCode == BillingSystemCode.Adc).Sum(y => y.PaymentAmount),
AmountNotAdc = x.Where(y => y.BillingSystemCode == BillingSystemCode.Exceed).Sum(y => y.PaymentAmount),
AmountTotal = x.Sum(y => y.PaymentAmount),
});
ScannedBatchCount = x.Count(y => y.BatchType == "S"),
ScannedBatchAmount = x.Where(y => y.BatchType == "S").Sum(y => y.PaymentAmount),
NonScannedBatchCount = x.Count(y => y.BatchType != "S"),
NonScannedBatchAmount = x.Where(y => y.BatchType != "S").Sum(y => y.PaymentAmount),
}).ToList()
};
第一的GroupBy工作正常,但是当我尝试GROUPBY批次场,我发现了以下生成错误:
错误76无效的匿名类型成员声明。匿名类型成员必须声明为成员分配,简单名称或成员访问权限。
错误在这里强调:
Batches = x.ToList().GroupBy(b => new { b => b.BatchCode })
有什么建议?
尝试'.GroupBy(b => new {BatchCode = b.BatchCode})' – slawekwin