Exemplo n.º 1
0
        public IPagedList <T> GetPagedList <T, TParams>(string name, long page, TParams prm = null)
            where T : class
            where TParams : class
        {
            var cmd = _commandManager.BeginTransaction();

            try
            {
                var pageSize = _dbOptions.PagedListSize;
                var offset   = pageSize * page;
                var sql      = _storedProcedureSql.GetStoredProcQuery(name, prm);
                sql = sql.AppendLimitOffset(pageSize, offset);
                _commandManager.PrepareCommandForExecution(sql, prm, cmd);
                //get the actual list into list property of pagedList;
                IList <T> list = Mapper.GetObjects <T>(cmd).ToList();
                //change the command text to get the count of the query query
                var countSql = _storedProcedureSql.GetStoredProcCountQuery(name, prm);
                _commandManager.PrepareCommandForExecution(countSql, prm, cmd);
                var count     = Mapper.ExecuteScalar <long>(cmd);
                var pagedList = new PagedList <T>(list, count, GetCurrentPage(pageSize, offset));
                _commandManager.CommitTransaction(cmd);
                return(pagedList);
            }
            catch
            {
                _commandManager.RollbackTransaction(cmd);
                throw;
            }
            finally
            {
                Utils.Dispose(cmd);
            }
        }
Exemplo n.º 2
0
        public IPagedList <T> GetPagedList(int page, string orderByColumn = "id")
        {
            var cmd = _commandManager.BeginTransaction();

            try
            {
                var mainSql = _sqlGenerator.GetPagedQuery(page, orderByColumn);
                _commandManager.PrepareCommandForExecution(mainSql, null, cmd);
                IList <T> list     = Mapper.GetObjects <T>(cmd).ToList();
                var       countSql = _sqlGenerator.GetCountQuery();
                _commandManager.PrepareCommandForExecution(countSql, cmd);
                var pagedList = new PagedList <T>(list, Mapper.ExecuteScalar <long>(cmd), page);
                _commandManager.CommitTransaction(cmd);
                return(pagedList);
            }
            catch
            {
                _commandManager.RollbackTransaction(cmd);
                throw;
            }
        }
Exemplo n.º 3
0
 public IDbCommand BeginTransaction()
 {
     return(_cmdManager.BeginTransaction());
 }