【发布时间】:2016-06-21 11:14:58
【问题描述】:
问题出在运行之后
reportData = dbContext.FinancialsBySupplierAuditPeriodStatusType
.Where(v => v.ReviewPeriodID == reportFilter.ReviewPeriodID && v.StatusCategoryID == reportFilter.StatusCategoryID)
.GroupBy(s => new { s.SupplierID })
.Select(g => new DrilldownReportItem {
SupplierID = g.Key.SupplierID,
SupplierName = g.Max(v => v.SupplierName),
AccountNo = g.Max(v => v.AccountNo),
TempTotals = g.Select(v => new TempTotals { ClaimType = v.TypeDesc ?? "Old Claims", Amount = v.Amount })
}).OrderBy(r => r.SupplierName).ToList();
Temp totals 是一个 IEnumerable,它包含一个简单类的 IEnumerable
public class TempTotals {
public string Type { get; set; }
public decimal? Amount { get; set; }
}
这个想法是然后将这些数据分组到一个字典中,这样我就可以得到所有数量的总和,键是类型。
最终结果应如下所示:
Dictionary<string, decimal> test = new Dictionary<string, decimal>() {
{"Claim",2 },
{"Query", 500 },
{"Normal", 700 }
};
我知道我可以只使用它,但是我正在寻找使用 LINQ 的解决方案。
【问题讨论】:
标签: c# entity-framework linq dictionary