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

前端 未结 14 1266
野性不改
野性不改 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:59

    The OP actually mentioned offset as well, so for ex. if you'd like to get the items from 30 to 60, you would do:

    var foo = (From t In MyTable
           Select t.Foo).Skip(30).Take(30);
    

    Use the "Skip" method for offset.
    Use the "Take" method for limit.

提交回复
热议问题