views:

366

answers:

2

I am sure this is a stupid question, but how would I get a pagedlist of filtered items?

Here is how I ended up doing it:

                PagedList<Company> company = Company.GetPaged(1, 10);


            var list = Company.Find(x => x.CompanyName.ToLower().Contains(query.ToLower()));
            company .Clear();

            foreach (var x in list)
                company .Add(x);

            return View(company );

In other words I want to do a find on the table, and return a paged list of the results.

Thanks!

A: 

There is a fantastic example of this in NerdDinner.

If you have trouble finding it then let me know and I'll post the code for ya.

griegs
Thanks, I looked at NerdDinner and found what you are talking about. I had trouble with it erroring out saying there was no aggregate or group by. I ended up solving it a little differently.
chad
A: 

Actually it's fairly easy to get the paged list and you said the answer in your question

In other words I want to do a find on the table, and return a paged list of the results.

  • Create your LINQ query (do a find on the table)
  • New up a SubSonic.Schema.PagedList(of T) (return a paged list)

For example:

var list = Company.Find(x => x.CompanyName.ToLower().Contains(query.ToLower()));
var paged = new SubSonic.Schema.PagedList<Company>(list,1,10)
Rick