linqsql-server-2008pagination

Linq selecting range of records


    var q = (from Comments in db.tblBlogComments where Comments.blogID == this.ID orderby Comments.date descending select new {
        Comments.userID, Comments.comment, Comments.date
    });

This returns ALL my associated records, how best would I select say records #10 to #20 only so I don't load any redundant data?


Solution

  • How about:

    var q = (
    from Comments in db.tblBlogComments 
    where Comments.blogID == this.ID 
    orderby Comments.date descending 
    select new { Comments.userID, Comments.comment, Comments.date }).Skip(10).Take(10);