.net Linq to SQL - 返回前 n 行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/787302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:35:04  来源:igfitidea点击:

Linq to SQL - Return top n rows

.netlinq-to-sql

提问by jinsungy

I want to return the TOP 100 records using Linq.

我想使用 Linq 返回前 100 条记录。

回答by tvanfosson

Use the Take extension method.

使用 Take 扩展方法。

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

回答by Lukasz

You want to use Take(N);

你想使用 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:

如果你也想跳过一些记录,你可以使用 Skip,它会跳过前 N 个数字:

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

回答by Michael Freidgeim

Example with order by:

订单示例:

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

回答by Scrappydog

Use Take()extension

使用Take()扩展

Example:

例子:

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