views:

64

answers:

2

I am building a MVC 2 application with SubSonic 3 - I have tried many differant paging methods and can find nothing that feels right.

I have a basic query that would be passed to a view which would loop and each iteration would call a strongly typed partial view.

        var SOQuestion= (
            from q in repo.All<SOQuestion>()
            orderby p.DateUpdated descending
            select p
            ).Skip(5).Take(10);

I want to be able to add filters where appropriate eg tag = "mvc" and/or user = "me" and at the same time page the results sensibly.

What solution is simple and neat?

+3  A: 

You can do that as follows:

var SOQuestion= (
        from q in repo.All<SOQuestion>()
        where tag =="mvc" && user == "me"
        orderby p.DateUpdated descending
        select p
        ).Skip(5).Take(10);
Lazarus
+3  A: 

You would use a where statement, as Lazarus describes.

If you need to do it dynamically (i.e. you don't know which fields you will be filtering on ahead of time), have a look at the Dynamic Linq library.

Robert Harvey
Good point on the Dynamic Linq library, there's a good primer on Scott Hanselman's blog: http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
Lazarus
thanks for this and agree dynamic linq is the way to go.In terms of presentation of the paging including getting counts and calculating next, last etc - is there a neat way to present this?
Desiny
There are some good ideas that you should be able to use here: http://www.c-sharpcorner.com/uploadfile/scottlysle/pagesortmvcincsharp03192009083337am/pagesortmvcincsharp.aspx
Robert Harvey