Last and LastOrDefault not supported

后端 未结 7 1069
孤独总比滥情好
孤独总比滥情好 2020-12-03 09:47

I am trying to get the first and last values in a list. The query operator First() is supported but Last() and LastOrDefault() give an

7条回答
  •  借酒劲吻你
    2020-12-03 10:09

    I try not to use LastOrDefault() because sometime it doesn't work or support. I'm sorting id by desc and then grab the first records.

    .OrderByDescending(o=>o.id)
    .FirstOrDefault(s => s.Name == Name)
    

提交回复
热议问题