Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq to SQL - Return top n rows

I want to return the TOP 100 records using Linq.

like image 896
jinsungy Avatar asked Apr 24 '09 19:04

jinsungy


2 Answers

Use the Take extension method.

var query = db.Models.Take(100);
like image 80
tvanfosson Avatar answered Nov 15 '22 07:11

tvanfosson


You want to use Take(N);

var data = (from p in people
           select p).Take(100);

If you want to skip some records as well you can use Skip, it will skip the first N number:

var data = (from p in people
           select p).Skip(100);
like image 57
Lukasz Avatar answered Nov 15 '22 07:11

Lukasz