Dapper-based paging implementation, support for filtering, sorting, total number of result sets, non-stored procedures

Source: Internet
Author: User

Brief introduction

The previous search for the next blog on the dapper paging implementation, there are, but either based on stored procedures, or support paging, not support sorting, or search conditions are not so easy to maintain.

Code

First on the code: https://github.com/jinweijie/Dapper.PagingSample

Method definition

The following is an implementation of my paging, though not generic (because of the Where condition and the collocation of the SQL statement), but it should be considered more generic, and the method is defined as follows:

 Public int> Find (logsearchcriteria criteria            int  pageIndex            int pageSize             string [] ASC             string [] desc);

The above function definition is an example of a query log, the return result, the first value of a tuple is the result set, the second value is the total number of rows (for example, there are 100 records, each page 10, the current first page, then the first value is 10 records, the second value is 100)

In the example project, I implemented the paging in two ways:

1. The first is based on 2 of this query, the first time to get the total, the second query to get the result set.

2. The second is based on 1 of this query, using SQL Server's Offest/fetch, so only support for 2012+, so people based on the version of SQL Server you use to choose different implementations, here is of course the second implementation of the higher efficiency.

Run the sample

1. Download or clone the GitHub repo to local, and then unzip the database directory to extract the database.7z

2. Attach to SQL Server. By default I use SQL Server LocalDB, the connection string is Data source= (LocalDB) \mssqllocaldb;initial catalog=dapperpagingsample;integrated   Security=true; If you are not using LOCALDB, modify the connection string for app. Config as appropriate.

3. Ctrl+f5 run the program, in the example project, I used a simple WinForm program, but it should be better to demonstrate the paging effect.

Thank you

Hope to be helpful to everyone:)

Dapper-based paging implementation, support for filtering, sorting, total number of result sets, non-stored procedures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.