How to implement SkipWhile with Linq to Sql without first loading the whole list into memory?

前端 未结 3 1052
天命终不由人
天命终不由人 2021-01-17 12:05

I need to order the articles stored in a database by descending publication date and then take the first 20 records after the article with Id == 100.

T

3条回答
  •  孤街浪徒
    2021-01-17 12:39

    You can try like this

    var articles = 
        db.Articles
        .Where(a => a.PublicationDate < db.Articles
                                        .Where(aa => aa.Id==100)
                                        .Select(aa => aa.PublicationDate)
                                        .SingleOrDefault())
        .OrderByDescending(a => a.PublicationDate)
        .Take(20);
    

提交回复
热议问题