Пример #1
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public List <T> FetchOrDefault <T>(string sql, params object[] args)
        {
            T        t    = Activator.CreateInstance <T>();
            List <T> list = new DataBaseAuxiliary(connectionString).DataReaderMultiple(t, sql, args).ToList();

            return(list);
        }
Пример #2
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public List <T> FetchOrDefault <T>()
        {
            T        t    = Activator.CreateInstance <T>();
            string   sql  = DataBaseAuxiliary.Current.SelectSQL(t, SqlQueryTypeEnum.FetchOrDefault);
            List <T> list = new DataBaseAuxiliary(connectionString).DataReaderMultiple(t, sql).ToList();

            return(list);
        }
Пример #3
0
        /// <summary>
        /// 分页-SQL server 2012 以下版本用
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="CurrentPage">当前页</param>
        /// <param name="PageSize">每页条数</param>
        /// <param name="sql">sql语句</param>
        /// <param name="args">参数</param>
        /// <returns></returns>
        private Page <T> PageOrDefaultForOld <T>(int CurrentPage, int PageSize, string sql, params object[] args)
        {
            T   t      = Activator.CreateInstance <T>();
            int count  = Convert.ToInt32(CountOrDefault <T>(sql, args));
            var list   = new DataBaseAuxiliary(connectionString).DataReaderMultiple(t, sql, args).Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList();
            var result = new Page <T>
            {
                PageIndex  = CurrentPage,
                PageSize   = PageSize,
                TotalItems = count,
            };

            result.TotalPages = result.TotalItems / PageSize;

            if ((result.TotalItems % PageSize) != 0)
            {
                result.TotalPages++;
            }
            result.Items = list;
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 分页-SQL server 2012 以上版本用
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="CurrentPage">当前页</param>
        /// <param name="PageSize">每页条数</param>
        /// <param name="sql">sql语句</param>
        /// <param name="args">参数</param>
        /// <returns></returns>
        private Page <T> PageOrDefaultForNew <T>(int CurrentPage, int PageSize, string sql, params object[] args)
        {
            T   t     = Activator.CreateInstance <T>();
            int count = Convert.ToInt32(CountOrDefault <T>(sql, args));

            sql = $@"{sql} OFFSET (({CurrentPage}-1)*{PageSize}) ROWS FETCH NEXT {PageSize} ROWS ONLY;";
            var list   = new DataBaseAuxiliary(connectionString).DataReaderMultiple(t, sql).ToList();
            var result = new Page <T>
            {
                PageIndex  = CurrentPage,
                PageSize   = PageSize,
                TotalItems = count,
            };

            result.TotalPages = result.TotalItems / PageSize;

            if ((result.TotalItems % PageSize) != 0)
            {
                result.TotalPages++;
            }
            result.Items = list;
            return(result);
        }