想要在查询月明智地总结费用

Want to sum fee in query month wise

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 类型的 Column "Fee" 求和并按 MonthID

分组

看看这个例子

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)));

键是月份和值的标识符 - 相应月份的费用总额。