views:

55

answers:

1

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?

A: 

You can still use PagedList. The IQueryable support is just one part, all of the other bits will work fine.

jfar
Right, but in order for things like HasNextPage, etc to work, don't I have to create a PagedList of all records returned from the query. So, if a user has 1000 messages, I have to then create a PagedList of all 1000 items. Not the 20 messages I need, and then set a total count
KingNestor