如何按月而不是按字母顺序排序此查询?我的数据库中有两列。一个代表月份名称,另一个代表月份编号。
现在,它按字母顺序订购了几个月。
var querythpmsick = (from r in db.SickLeaveRequestForms
where r.EmployeeID == id
group r by r.MonthOfHoliday into g
select new { Value = g.Key, Count1 = g.Sum(h => h.SickLeaveTaken) }
).OrderBy(e => e.Value);
答案 0 :(得分:0)
如果您的数据库中同时包含月份名称和月份编号,则只需按数字而不是月份名称进行分组:
var querythpmsick = (from r in db.SickLeaveRequestForms where r.EmployeeID == 2
group r by r.MonthOfHolidayInt into g
select new { Value = g.Key, Count1 = g.Sum(h => h.SickLeaveTaken), MonthName = g.Select(d => d.MonthOfHoliday) })
.OrderBy(e => e.Value);
以下是一个DotNetFiddle,示例:https://dotnetfiddle.net/6vE4lo