We have a method where we go get People. We are using EF and Ria Services. With the way things are now we call GetPeople and in one situation(example) we get back 920 people. We fill a grid with all this information. We have decided since our app is growing that we should put a cap on this - 500. We have a series of filters we can use as well. Year is one of them. So when I put a filter of 2012 on our search I return 460 people. Our code went from this
return _personSearchRepository.All().Where(x => x.ProgramID == programID && x.PersonType == "Person");
to
return _personSearchRepository.All().Where(x => x.ProgramID == programID && x.PersonType == "Person").Take(500);
we added the Take(500) - problem is when we added this code the first search with no filters returned 500 people - no problems here. But when we add the year filter - where I would expect 460 to be brought back I got 79. I took the Take out and I was back to getting 460.
If you add the year filter after the .Take(500)
, then the filter is applied to those 500 persons. You will have to create a second method or modify the existing one to include a parameter for the filter, which can then be applied before you call .Take(500)
.
I assume that your methods return IQueryable<Person>
, in which case a filter applied on the client will basically result in something like this:
_personSearchRepository.All().Where(x => x.ProgramID == programID
&& x.PersonType == "Person")
.Take(500).Where(x => x.CreatedYear = 2012);
If you modify the method to look like this:
IQueryable<Person> GetPersonsWithYearFilter(int year)
{
return _personSearchRepository.All().Where(x => x.ProgramID == programID
&& x.PersonType == "Person" && x.CreatedYear = year)
.Take(500);
}
then it should work.
The above code is not tested.