var TotalFee = (from item in _dbEntities.MonthlyFees
where item.Year == DateTime.Now.Year &&
item.FeeStatus == true
select item).GroupBy(x =>x.MonthID);//.AsEnumerable().Sum(x => int.Parse(x));
我想将列“费用”加上nvarchar类型并将其按MonthID
分组答案 0 :(得分:0)
请看这个例子
var feesDictionary = _dbEntities.MonthlyFees
.Where(x => x.Year.Equals(DateTime.Now.Year) && x.FeeStatus)
.GroupBy(x => x.MonthID)
.ToDictionary(x => x.Key, x => x.Sum(y => Convert.ToDouble(y.Fee)));
密钥是月份和值的标识符 - 适当月份的费用总和。