Beispiel #1
0
        public static T Load <T>(this SqlConnection connection, MySearchUtil util = null, SqlTransaction trans = null, string table = "")
        {
            util  = util ?? new MySearchUtil();
            table = string.IsNullOrWhiteSpace(table) ? MyContainer.Get(typeof(T)).Table : table;

            var where = util.GetWhere();
            var orderBy = util.GetOrderBy();
            var param   = util.GetParam();

            var sql = $"SELECT TOP 1 * FROM [{table}] WHERE {where} ORDER BY {orderBy}";

            return(connection.QueryFirst(sql, param, trans));
        }
Beispiel #2
0
        public static List <T> Fetch <T>(this SqlConnection connection, string table, MySearchUtil util = null, string cols = "*", int top = 0)
        {
            cols = string.IsNullOrWhiteSpace(cols) ? "*" : cols;
            util = util ?? new MySearchUtil();

            var where = util.GetWhere();
            var param   = util.GetParam();
            var orderBy = util.GetOrderBy();

            var topStr = top > 0 ? $" TOP {top}" : "";

            var sql = $"SELECT{topStr} {cols} FROM [{table}] WHERE {where} ORDER BY {orderBy}";

            return(connection.Query <T>(sql, param).ToList());
        }
Beispiel #3
0
        public static PageList <T> PageList <T>(this SqlConnection connection,
                                                string table, int pageIndex, int pageSize, MySearchUtil util, string cols = "*")
        {
            if (util == null)
            {
                throw new ArgumentNullException(nameof(util), "查询参数不能为空");
            }

            var where = util.GetWhere();
            var param   = util.GetParam(true);
            var orderBy = util.GetOrderBy();

            var sql  = SqlBuilder.GetPaginSelect(table, cols, where, orderBy, pageIndex, pageSize);
            var body = connection.Query <T>(sql, param);

            return(new PageList <T>
            {
                Body = body.ToList(),
                PageIndex = pageIndex,
                PageSize = pageSize,
                RecordCount = param.Get <int>("RecordCount")
            });
        }