Search code examples
pagingdapper

Dapper. Paging


I am trying Dapper ORM and I am querying a a Posts table.

But I would like to get paged results ...

1 - How can I do this? Isn't there a helper for this?

2 - Can Dapper Query return an IQueryable?

Thank You, Miguel


Solution

  • 1) Dapper doesn't have a built-in pagination feature. But its not too hard to implement it directly in the query. Example:

    SELECT  *
    FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY InsertDate) AS RowNum, *
              FROM      Posts
              WHERE     InsertDate >= '1900-01-01'
            ) AS result
    WHERE   RowNum >= 1 // *your pagination parameters
        AND RowNum < 20  //*
    ORDER BY RowNum
    

    Requires SQL Server 2005+

    2) Dapper returns an IEnumerable<T>.