phnx47 / dapper-repositories

CRUD for Dapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Count SetLimit FindAll method supports custom sql

apchenjun opened this issue · comments

This is the code I used in my project after transformation,Because I need multi-table related query.

public Task<int> CountAsync(string customSql, object parameters = null)
        {
            string pagedListSql = @$"select count(*) from ({customSql}) counttbl";
            return Connection.QueryFirstAsync<int>(pagedListSql, parameters,  _unitofWork.DbTransaction, Timeout);
        }

        public Task<IEnumerable<TEntity>> GetAllPagedAsync(string customSql, int pageNumber, int itemsPerPage, string orderby, object parameters = null, bool buffered = true)
        {
            string pagedListSql = @$"select * from ({customSql}) pagetable ORDER BY {orderby} OFFSET { (pageNumber - 1) * itemsPerPage  } ROWS FETCH NEXT { itemsPerPage} ROWS only ";
            return Connection.QueryAsync<TEntity>(pagedListSql, param: parameters, transaction: _unitofWork.DbTransaction, commandTimeout: Timeout);
        }

In my project I need to use it like this
image

@apchenjun Feel free to raise PR

@phnx47 I only implemented the sqlserver version and other database versions. Someone needs to implement it.

Nobody interesting to implement it...