views:

270

answers:

1

In the Repository there is a GetPagedList method.

I have a method that expects a return of PagedList

I currently have

return _repository.GetPaged(sortBy, pageNumber, 20);

However I now need to do some checking such as

_repository.GetPaged(sortBy, pageNumber, 20).Where(x => x.IsAdmin == false)

This now changes type to IEnumerable. I have tried doing a Cast>() but that doesn't work either.

Any help appreciated!

+2  A: 

Just faced the same problem, and found that you can create your own PagedList<> passing in a customisable IQueryable object. Seen below you add your own where clauses, before paginating.

IQueryable<YourObject> yourQuery = _repository.All().Where(x => x.IsAdmin == false);

return new PagedList<YourObject>(yourQuery, pageNo, pageSize);

You might need to add an OrderBy clause, as i think it's either a bug or design limitation (V3.03) not using primary key as the default order column.

I'm sure this would be considered in later versions as its pretty rare to paginate without any where clause, and wouldn't be much work to updated the tt templates.

timpeck
excellent, i am using this method now and works great
minus4