Beispiel #1
0
        public List <T> ToList <T>(DBBuilder dbBuilder, string sortExpression = null) where T : new()
        {
            if (sortExpression == null)
            {
                return(this.Do(dbBuilder, connection => connection.Query <T>(dbBuilder.GetCommand(DBAdapter)).ToList()));
            }

            dbBuilder.Compile(this.DBAdapter);
            var dbAnalyzer = DBAnalyzer.Init(dbBuilder.Sql, null, null, sortExpression);

            dbBuilder.Sql = dbAnalyzer.Select();
            return(this.Do(dbBuilder, connection => connection.Query <T>(dbBuilder.GetCommand(DBAdapter)).ToList()));
        }
Beispiel #2
0
        /// <summary>
        /// 执行SQL语句并获取返回值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dbBuilder"></param>
        /// <returns></returns>
        public PagedList <T> ToList <T>(DBBuilder dbBuilder, int pageIndex = 1, int pageSize = 15, string sortExpression = null) where T : new()
        {
            dbBuilder.Compile(this.DBAdapter);
            var dbAnalyzer = DBAnalyzer.Init(dbBuilder.Sql, pageIndex, pageSize, sortExpression);

            dbBuilder.Sql = dbAnalyzer.Count();
            var count = Convert.ToInt32(ToScalar(dbBuilder));

            dbBuilder.Sql = dbAnalyzer.Select();
            return(new PagedList <T>
            {
                CurrentPage = pageIndex,
                ItemsPerPage = pageSize,
                TotalItems = count,
                TotalPages = count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1,
                Items = ToList <T>(dbBuilder)
            });
        }
Beispiel #3
0
        public PagedList ToDataTable(DBBuilder dbBuilder, int pageIndex, int pageSize, string sortExpression = null)
        {
            dbBuilder.Compile(this.DBAdapter);
            var dbAnalyzer = DBAnalyzer.Init(dbBuilder.Sql, pageIndex, pageSize, sortExpression);

            dbBuilder.Sql = dbAnalyzer.Count();
            var count = Convert.ToInt32(ToScalar(dbBuilder));

            dbBuilder.Sql = dbAnalyzer.Select();
            return(new PagedList
            {
                CurrentPage = pageIndex,
                ItemsPerPage = pageSize,
                TotalItems = count,
                TotalPages = count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1,
                Items = ToDataTable(dbBuilder).AsEnumerable().ToList(),
            });
        }
 /// <summary>
 /// 获得请求的命令
 /// </summary>
 /// <param name="dbBuilder"></param>
 /// <returns></returns>
 public static CommandDefinition GetCommand(this DBBuilder dbBuilder, IDBAdapter dbAdapter)
 {
     return(new CommandDefinition(dbBuilder.Compile(dbAdapter).Sql, dbBuilder.Parameters.Instance, dbBuilder.Transaction, null, dbBuilder.CommandType));
 }