Linq to SQL-返回顶部 n 行

我想使用 Linq 返回 TOP 100记录。

97659 次浏览

Use the Take extension method.

var query = db.Models.Take(100);

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);

Use Take() extension

Example:

var query = (from foo in bar).Take(100)

Example with order by:

var data = (from p in db.people
orderby p.IdentityKey descending
select p).Take(100);