88

I want to return the TOP 100 records using Linq.

jinsungy
  • 10,717
  • 24
  • 71
  • 79

4 Answers4

146

Use the Take extension method.

var query = db.Models.Take(100);
tvanfosson
  • 524,688
  • 99
  • 697
  • 795
58

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);
Lukasz
  • 8,710
  • 12
  • 44
  • 72
14

Example with order by:

var data = (from p in db.people  
            orderby p.IdentityKey descending 
            select p).Take(100); 
Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
2

Use Take() extension

Example:

var query = (from foo in bar).Take(100)
Mazdak Shojaie
  • 1,620
  • 1
  • 25
  • 32
Scrappydog
  • 2,864
  • 1
  • 21
  • 23