Пример #1
0
        public static int Delete <T>(this SqlConnection connection, T entity, SqlTransaction trans = null) where T : BaseEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;
            var sql   = $"DELETE [{table}] WHERE Id=@Id";

            return(connection.Execute(sql, new { entity.Id }, trans));
        }
Пример #2
0
        public static int Remove <T>(this SqlConnection connection, int[] ids, SqlTransaction trans = null)
            where T : BaseEntity, IRemoveAble
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Remove(table, ids, trans));
        }
Пример #3
0
        public static int Remove <T>(this SqlConnection connection, int[] ids, BaseAppUser user, SqlTransaction trans = null)
            where T : TraceEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Remove(table, ids, user, trans));
        }
Пример #4
0
        public static int Remove <T>(this SqlConnection connection, List <T> entities, SqlTransaction trans = null)
            where T : BaseEntity, IRemoveAble
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Remove(table, entities.Select(e => e.Id).ToArray(), trans));
        }
Пример #5
0
        public static T Load <T>(this SqlConnection connection, int id, SqlTransaction trans = null, string table = "")
        {
            table = string.IsNullOrWhiteSpace(table) ? MyContainer.Get(typeof(T)).Table : table;
            var sql = $"SELECT TOP 1 * FROM [{table}] WHERE Id=@Id";

            return(connection.QueryFirst(sql, new { Id = id }, trans));
        }
Пример #6
0
        public static int Delete <T>(this SqlConnection connection, List <T> entities, SqlTransaction trans = null) where T : BaseEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;
            var sql   = $"DELETE [{table}] WHERE Id IN @Ids";

            return(connection.Execute(sql, new { Ids = entities.Select(e => e.Id) }, trans));
        }
Пример #7
0
        public static int Remove <T>(this SqlConnection connection, IEnumerable <T> entities, BaseAppUser user, SqlTransaction trans = null)
            where T : TraceEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Remove(table, entities.Select(e => e.Id).ToArray(), user, trans));
        }
Пример #8
0
        public static int Remove <T>(this SqlConnection connection, BaseAppUser user, MySearchUtil util, SqlTransaction trans = null)
            where T : BaseEntity
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Remove(table, user, util, trans));
        }
Пример #9
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));
        }
Пример #10
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));
        }
Пример #11
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));
        }
Пример #12
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));
        }
Пример #13
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));
        }
Пример #14
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));
        }
Пример #15
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));
        }
Пример #16
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));
        }
Пример #17
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));
        }
Пример #18
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));
        }
Пример #19
0
        public static int Delete <T>(this SqlConnection connection, MySearchUtil util = null)
        {
            var table = MyContainer.Get(typeof(T)).Table;

            return(connection.Delete(table, util));
        }
Пример #20
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));
        }