Last and LastOrDefault not supported

后端 未结 7 1088
孤独总比滥情好
孤独总比滥情好 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:16

    Last is not supported by the back-end DB. You should try other techniques:

    1. Run your query using OrderByDescending so your requested item comes first.

    2. Code your LINQ query as usual, but enforce Linq2Sql to render it to a CLR collection and then you'll have free access to everything locally, including Last. Example:

      var bills = purchaseBills.ToList();
      var last = bills.Last();
      

提交回复
热议问题