开发者

how to add one extra temporary entity in collection returned by LINQ

here my code-

List<ReservationSlotLimitDetailEntity> sorted = (from p in slotLimitCollection.OfType<ReservationSlotLimitDetailEntity>()
            where p.DayOfTheWeek == dayOfTheWeek
 开发者_运维百科           select p).ToList<ReservationSlotLimitDetailEntity>();

I want to sort in such a way so that it will add on more temp column "DayName" based on condition such that if dayOfTheWeek==1 DayName=Monday and if dayOfTheWeek==2 DayName=Tuesday and so on.


  1. Add string DayName as a property of the ReservationSlotLimitDetailEntity class
  2. Add a function GetDayName(int dayOfTheWeek) that translates dayOfTheWeek values into the text that you want (switch structure, case 1: return "Monday", etc.
  3. After you retrieve your data, do the following:

    sorted.ForEach(x => x.DayName = GetDayName(dayOfTheWeek);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜