I'm working on a messaging system for a site of mine written in ASP.NET MVC. Right now, I'm attempting to iron out Pagination for the Inbox/Sent views.
I've stumbled onto Rob Connery's PagedList<T>
, which seems like a nice solution to the problem.
However, one difference between my use-case and Rob's however is that I don't return IQueryable from my Model, and all queries I run with .ToList() after them (then returning an IEnumerable), to ensure that my query is executed when the Model's method is called.
Because of this difference, does it still make sense to use his PagedList<T>
? I basically just want to return a subset of the total results, along with some other properties like "HasNextPage", "Total Count", etc.
However, because I'm not letting the PagedList class call an IQueryable directly, I'm wondering if I should just create my own basic class with those properties that I want?
I know how to take a particular page of results using LINQ:
public IEnumerable<Entities.Message> GetInboxMessages(int userID, int pageSize, int pageIndex)
{
using (MainDataContext db = new MainDataContext())
{
var messages = (from m in db.Messages
join o in db.MessageRecipients on m.MessageID equals o.MessageID
orderby m.DateSent
select new Entities.Message
{
// ...
}).Skip(pageIndex * pageSize).Take(pageSize).ToList();
return messages;
}
}
But without the other information I need about HavingNextPage, TotalItemsCount, etc.
What should I do in this case? Can I still use the above PagedList<T>
, even though I don't plan on doing Lazy Loading? Should I just create my own?