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

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

How do I do this

Select top 10 Foo from MyTable

in Linq to SQL?

14条回答
  •  一生所求
    2020-12-12 16:00

    I had to use Take(n) method, then transform to list, Worked like a charm:

        var listTest = (from x in table1
                         join y in table2
                         on x.field1 equals y.field1
                         orderby x.id descending
                         select new tempList()
                         {
                             field1 = y.field1,
                             active = x.active
                         }).Take(10).ToList();
    

提交回复
热议问题