Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public static int UpdateExclude <T>(this SqlConnection connection, string[] columns, T entity, SqlTransaction trans = null) where T : BaseEntity
        {
            var model = MyContainer.Get(typeof(T));
            var table = model.Table;

            var allColumns = model.Properties.Where(p => p.PropertyName != "Id").Select(p => p.PropertyName);
            var cols       = allColumns.Except(columns).ToList();

            if (!cols.Any())
            {
                throw new ArgumentNullException("未包含有效要更新的列");
            }

            var sql = $"UPDATE [{table}] SET {string.Join(",", cols.Select(c => $"{c}=@{c}"))} WHERE Id=@Id";

            return(connection.Execute(sql, entity, trans));
        }
Ejemplo n.º 3
0
        public static int Update <T>(this SqlConnection connection, int[] ids, KeyValuePairs kvs, SqlTransaction tran = null) where T : BaseEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Update(table, kvs, ids));
        }
Ejemplo n.º 4
0
        public static int Update <T>(this SqlConnection connection, List <T> entities, SqlTransaction trans = null) where T : BaseEntity
        {
            var sql = MyContainer.Get(typeof(T)).UpdateSqlStatement;

            return(connection.Execute(sql, entities, trans));
        }
Ejemplo n.º 5
0
        public static int Count <T>(this SqlConnection connection, MySearchUtil util = null, SqlTransaction trans = null) where T : BaseEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Count(table, util, trans));
        }
Ejemplo n.º 6
0
        public static PageList <T> PageList <T>(this SqlConnection connection, int pageIndex, int pageSize, MySearchUtil util, string cols = "*")
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.PageList <T>(table, pageIndex, pageSize, util, cols));
        }
Ejemplo n.º 7
0
        public static List <T> Fetch <T>(this SqlConnection connection, MySearchUtil util = null, string cols = "*", int top = 0)
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Fetch <T>(table, util, cols, top));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 创建实体
        /// </summary>
        /// <typeparam name="T">BaseEntity</typeparam>
        /// <param name="conn"></param>
        /// <param name="entity">要创建的实体</param>
        /// <param name="trans">事务</param>
        /// <returns>实体的Id</returns>
        public static int Create <T>(this SqlConnection conn, T entity, SqlTransaction trans = null) where T : BaseEntity
        {
            var sql = MyContainer.Get(typeof(T)).InsertSqlStatement;

            return(conn.ExecuteScalar <int>(sql, entity, trans));
        }
Ejemplo n.º 9
0
        public static int Delete <T>(this SqlConnection connection, MySearchUtil util = null)
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Delete(table, util));
        }
Ejemplo n.º 10
0
        public static int Delete <T>(this SqlConnection connection, int[] ids) where T : BaseEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Delete(table, ids));
        }
Ejemplo n.º 11
0
        public static int Delete <T>(this SqlConnection connection, int id, SqlTransaction trans = null) where T : BaseEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Delete(table, id, trans));
        }
Ejemplo n.º 12
0
        public static int Update <T>(this SqlConnection connection, KeyValuePairs kvs, MySearchUtil util, SqlTransaction trans = null)
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Update(table, kvs, util, trans));
        }