Sort by month in linq and EF

后端 未结 5 2034
傲寒
傲寒 2021-01-28 17:09

I have a linq query and inside of it is the month name. I want the results sorted by the month (Jan, Feb, Mar, ...).

Currently I have the below but it\'s giving me and e

5条回答
  •  无人及你
    2021-01-28 17:22

    Something like this should work

    var shockValues = ctx.Shocks.Where(s => s.ID == id).Select(x => new {x.MonthName, MonthNum = x.MonthName == "Jan" : 1 ? x.MonthName == "Feb" : 2 ? 0}).OrderBy(s => MonthNum).Select(s => new {val = s.MonthName + "=" + s.ShockValue}     
    

提交回复
热议问题