What's the Linq to SQL equivalent to TOP or LIMIT/OFFSET?

前端 未结 14 1237
野性不改
野性不改 2020-12-12 15:19

How do I do this

Select top 10 Foo from MyTable

in Linq to SQL?

14条回答
  •  粉色の甜心
    2020-12-12 15:57

    Array oList = ((from m in dc.Reviews
                               join n in dc.Users on m.authorID equals n.userID
                               orderby m.createdDate descending
                               where m.foodID == _id                      
                               select new
                               {
                                   authorID = m.authorID,
                                   createdDate = m.createdDate,
                                   review = m.review1,
                                   author = n.username,
                                   profileImgUrl = n.profileImgUrl
                               }).Take(2)).ToArray();
    

提交回复
热议问题