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! :)

Was it helpful?

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

OTHER TIPS

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top