Linq to SQL - returns the top n rows

I want to return TOP 100 records using Linq.

+71
linq-to-sql
Apr 24 '09 at 19:47
source share
4 answers

Use the Take extension method.

var query = db.Models.Take(100); 
+121
Apr 24 '09 at 19:48
source share
β€” -

Do you want to use Take (N);

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

If you want to skip some entries, you can also use Skip, it will skip the first number N:

 var data = (from p in people select p).Skip(100); 
+53
Apr 24 '09 at 19:49
source share

Example with order:

 var data = (from p in db.people orderby p.IdentityKey descending select p).Take(100); 
+10
Jun 03 '11 at 6:30
source share

Use the Take() extension

Example:

 var query = (from foo in bar).Take(100) 
+1
Apr 24 '09 at 19:51
source share



All Articles