View on GitHub

MicroDBHelper-ExpansionPack

Optional Expansion Packs for [MicroDBHelper]

icon

ExpansionPack :: PagingQuery

This expansion pack is focus on paging query.

The root section of documents of all optional expansion packs, please visit here.

Environmental Requirement

Generated for Framework Version:

Dependencies

Usage

Internal logic

The library will automatically choose the best way to do paging query.

When the Product Version of SQLServer Instance is 11.0.x.x (SQLServer 2012) or higher, it will use the OFFSET FETCH way;

Otherwise, it will use the ROW_NUMBER() way, which was supported from SQLServer 2005.

Result container

Firstly, let us see the result models, PagingResult and PagingResult<T>.

The former include DataTable object result, the latter include entity list of target type result.

  PagingResult PagingResult<T>
.Datas DataTable IList<T>
.CurrentPageIndex Current Index Current Index
.PageSize Size of per Page Size of per Page
.TotalItemsCount Count of all items Count of all items
.TotalPages Count of all pages Count of all pages

Call query method

Paging datas by Database

There are two alternatives in MicroDBHelpers.ExpansionPack.PagingQuerier static class :

There are some key parameters in these query methods:

More about fixedSql and selectSql :

snapshot

Directly paging entities In Memory

This is Just a helper function for developers who hope to “Paging Datas in Memory” and use the “PagingResult Model”,it is in MicroDBHelpers.ExpansionPack.PagingQuerier static class.

//Method definition:
PagingResult<T> PagingByList<T>(IEnumerable<T> datas, int pageIndex, int pageSize);

Notes & Recommend

The Core logic of Paging Query is to change the T-SQL, SELECT the total count of results, and SELECT the datas PART of them thanks to ROW_NUMBER function and Offset Fetch function . So in fact, the origin T-SQL you pass into the method cannot be very complex, it’s a hard work to deal all of the complex situations.

:) However, there are some recommends that can make it work fine:

It should be noted that, fields that appear ORDER-BY part, must appear SELECT part as well.
These scenes is okay:

snapshot

Download compiled binary file

If you needn’t to got the code and bulid by yourself for the moment, I also offer the newest compiled file in the BUILD directiory for your convenience.

Build Directory

NuGet

Install-Package MicroDBHelper-ExpansionPack-PagingQuery link




o(∩_∩)o The root section of documents of all optional expansion pack, please visit here.