Count SetLimit FindAll method supports custom sql
apchenjun opened this issue · comments
O0oo0O commented
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);
}
Serge K commented
@apchenjun Feel free to raise PR
O0oo0O commented
@phnx47 I only implemented the sqlserver version and other database versions. Someone needs to implement it.
Serge K commented
Nobody interesting to implement it...