General-purpose generic paging based on dapper

Source: Internet
Author: User

1. Define a paging result class that is used to load all classes
public class pagedataview<t>{Private int _totalnum, public pagedataview () {this._items = new list<t> ();} public int Totalnum{get {return _totalnum;} set {_totalnum = value;}} Private ilist<t> _items;public ilist<t> items{get {return _items;} set {_items = value;}} public int CurrentPage {get; set;} public int Totalpagecount {get; set;}}

  

Pagedataview items A generic attribute, so it can be suitable for all classes, concise and universal.

Here's how to use the generic dapper common class for universal paging:

public static pagedataview<msys_admin> GetList (string name, string loginName, int page,int pagesize=10) { Pagecriteria criteria = new Pagecriteria (); criteria. Condition = "1=1"; if (!string. IsNullOrEmpty (name)) criteria. Condition + = string. Format ("and name like '%{0}% '", name); if (!string. IsNullOrEmpty (LoginName)) criteria. Condition + = string. Format ("and LoginName like '%{0}% '", LoginName); criteria. CurrentPage = Page;criteria. Fields = "*"; criteria. PageSize = Pagesize;criteria. TableName = "Sys_admin a"; criteria. PrimaryKey = "UID"; var r = common.getpagedata<msys_admin> (criteria); return r;}

Reference URL:

Http://www.lanhusoft.com/Article/130.html

General-purpose generic paging based on dapper

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.