Esempio n. 1
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="util">查询参数</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="table">要查询的表</param>
        /// <param name="cols">要查询的列</param>
        /// <returns></returns>
        public PageList <T> Query <T>(MySearchUtil util, int pageIndex, int pageSize, string table = "", string cols = "*")
        {
            if (string.IsNullOrWhiteSpace(table))
            {
                table = GetTableName(typeof(T));
            }

            string where = util.GetConditionClaus();
            string            orderby = util.GetOrderByClaus();
            DynamicParameters param   = util.GetPageListParameters();

            string sql = GetPagingQuerySql(cols, table, where, orderby, pageIndex, pageSize);

            using (var conn = GetConnection())
            {
                var list  = conn.Query <T>(sql, param);
                var total = param.Get <int>("RecordCount");
                return(new PageList <T>
                {
                    Body = list,
                    PageIndex = pageIndex,
                    PageSize = pageSize,
                    RecordCount = total
                });
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 加载实体
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="util"></param>
 /// <param name="cols"></param>
 /// <returns></returns>
 public T Load <T>(MySearchUtil util, string cols = "*")
 {
     using (var conn = GetConnection())
     {
         string sql = "SELECT TOP 1 " + cols + " FROM [" + GetTableName(typeof(T)) + "] WHERE " +
                      util.GetConditionClaus() + (string.IsNullOrWhiteSpace(util.GetOrderByClaus()) ? "" : " ORDER BY " + util.GetOrderByClaus());
         return(conn.Query <T>(sql, util.GetParameters()).SingleOrDefault());
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 获取指定表的所有数据,返回dynamic类型的数据列表
        /// </summary>
        /// <param name="util">查询参数</param>
        /// <param name="table">要查询的表</param>
        /// <param name="cols">要查询的列</param>
        /// <param name="top">指定数量</param>
        /// <returns></returns>
        public IEnumerable <dynamic> Fetch(MySearchUtil util, string table, string cols = "*", int?top = null)
        {
            string where = util.GetConditionClaus();
            string            orderby = util.GetOrderByClaus();
            DynamicParameters param   = util.GetParameters();

            string sql = GetQuerySql(cols, table, where, orderby);

            using (var conn = GetConnection())
            {
                return(conn.Query(sql, param));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 获取所有数据
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="util">查询参数</param>
        /// <param name="table">查询的数据表</param>
        /// <param name="cols">要查询的列</param>
        /// <param name="top">要获取的数量</param>
        /// <returns></returns>
        public IEnumerable <T> Fetch <T>(MySearchUtil util, string table = "", string cols = "*", int?top = null)
        {
            if (string.IsNullOrWhiteSpace(table))
            {
                table = GetTableName(typeof(T));
            }

            string where = util.GetConditionClaus();
            string            orderby = util.GetOrderByClaus();
            DynamicParameters param   = util.GetParameters();

            string sql = GetQuerySql(cols, table, where, orderby, top);

            using (var conn = GetConnection())
            {
                return(conn.Query <T>(sql, param));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 获取分页动态数据列表
        /// </summary>
        /// <param name="util">查询参数</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页条数</param>
        /// <param name="table">要查询的表</param>
        /// <param name="cols">要查询的列</param>
        /// <returns></returns>
        public PageList <dynamic> Query(MySearchUtil util, int pageIndex, int pageSize, string table, string cols = "*")
        {
            string where = util.GetConditionClaus();
            string            orderby = util.GetOrderByClaus();
            DynamicParameters param   = util.GetPageListParameters();

            string sql = GetPagingQuerySql(cols, table, where, orderby, pageIndex, pageSize);

            using (var conn = GetConnection())
            {
                var list  = conn.Query(sql, param);
                var total = param.Get <int>("RecordCount");
                return(new PageList <dynamic>
                {
                    Body = list,
                    PageIndex = pageIndex,
                    PageSize = pageSize,
                    RecordCount = total
                });
            }
        }