Question

a question on how to add a "SELECT TOP" query in asp.net mvc3

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

in my applicant there is i think 200,000 datas and i just want to select the top 50

is that possible? Thanks KUDOS! :)

Était-ce utile?

La solution

To return the top 50 rows in any order

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

if you want to apply ordering, say there's a LastName field

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

Autres conseils

Use Take and Skip accordingly. For example, to take second 10 applicants:

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

Use the Take extension method:

var applicant = (from s in applicantRepository.GetApplicant()
                       select s).Take(50);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top