When we were setting up paging for the users grid, the social wall, and the wiki history we were noticing that the paging code we have in the data layer was loading the entire result set unpaged. This of course is a major scalabity problem. We found a solution to this problem while solving another problem of doing generic sorting on entities using expression trees.
As I am sure you know by now you have to sort before doing a skip in entity. If you check out the QueryExtensions in MvcCms.Service.Code (where we got this from) you will see we are calling it like below. Using the QueryExtensions SortBy<T> method keeps the paging from pulling the entire table. We also have setup a custom sproc to get the total rows for the result set as this performs better and keeps the paging code from pulling everything into an entity.
As I am sure you know by now you have to sort before doing a skip in entity. If you check out the QueryExtensions in MvcCms.Service.Code (where we got this from) you will see we are calling it like below. Using the QueryExtensions SortBy<T> method keeps the paging from pulling the entire table. We also have setup a custom sproc to get the total rows for the result set as this performs better and keeps the paging code from pulling everything into an entity.
var messages = QueryExtensions .SortBy
(
_repository.ListSocialMessages(userId)
.AsQueryable(), "AddedDate DESC"
)
.AsPagination(pageNumber, resultsPerPage)
.ToList();
6 months 25 days
ago by
jon
