1

关于如何在 asp.net mvc3 中添加“SELECT TOP”查询的问题

            var applicant = from s in applicantRepository.GetApplicant()
                       select s;

在我的申请人中,我认为有 200,000 个数据,我只想选择前 50 个

那可能吗?谢谢库多斯!:)

4

3 回答 3

2

以任意顺序返回前 50 行

var applicant = 
    (from s in applicantRepository.GetApplicant()
    select s).Take(50);

如果你想申请排序,说有一个姓氏字段

var applicant = 
    (from s in applicantRepository.GetApplicant()
    orderby s.LastName
    select s).Take(50);
于 2013-05-06T07:02:22.780 回答
2

相应地使用TakeSkip。例如,要录取后 10 名申请人:

var applicant = 
  (from s in applicantRepository.GetApplicant()
   select s).Skip(10).Take(10);
于 2013-05-06T07:04:05.373 回答
1

使用 Take 扩展方法:

var applicant = (from s in applicantRepository.GetApplicant()
                       select s).Take(50);
于 2013-05-06T07:04:13.270 回答