示例#1
0
 /// <summary>
 /// Bulk Delete with given table name
 /// </summary>
 /// <param name="db"></param>
 /// <param name="tableName"></param>
 /// <param name="tran"></param>
 public static void BulkDelete(this SqlConnection db, string tableName, SqlTransaction tran = null)
 {
     using (var sbc = new SqlBulkDelete(db, tran))
     {
         sbc.BulkDelete(tableName);
     }
 }
示例#2
0
        /// <summary>
        /// 清空数据所有数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        public static void BulkDelete <T>(this SqlConnection db)
        {
            var tableName = typeof(T).Name;

            using (var sbc = new SqlBulkDelete(db))
            {
                sbc.BulkDelete(tableName);
            }
        }
示例#3
0
        /// <summary>
        /// 批量删除数据(支持NotMapped属性)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TPk"></typeparam>
        /// <param name="db"></param>
        /// <param name="dt"></param>
        /// <param name="columnPrimaryKeyExpression"></param>
        /// <param name="tran"></param>
        /// <returns>受影响行</returns>
        public static int BulkDelete <T, TPk>(this SqlConnection db, List <T> dt, Expression <Func <T, TPk> > columnPrimaryKeyExpression, SqlTransaction tran = null) where T : new()
        {
            if (columnPrimaryKeyExpression == null)
            {
                throw new Exception("columnPrimaryKeyExpression不能为空");
            }

            var pkColumns = GetColumns(columnPrimaryKeyExpression);

            if (pkColumns.Count == 0)
            {
                throw new Exception("主键不能为空");
            }

            var tableName = typeof(T).Name;

            using (var sbc = new SqlBulkDelete(db, tran))
            {
                return(sbc.BulkDelete(tableName, dt, pkColumns));
            }
        }
示例#4
0
        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        /// <param name="dt"></param>
        /// <param name="columnPrimaryKeyExpression"></param>
        /// <returns>受影响行</returns>
        public static int BulkDelete <T>(this SqlConnection db, List <T> dt, Func <T, object> columnPrimaryKeyExpression) where T : new()
        {
            if (columnPrimaryKeyExpression == null)
            {
                throw new Exception("columnPrimaryKeyExpression不能为空");
            }

            var t     = new T();
            var pkObj = columnPrimaryKeyExpression.Invoke(t);
            var pks   = Common.GetColumns(pkObj);

            if (pks.Length == 0)
            {
                throw new Exception("主键不能为空");
            }

            var tableName = typeof(T).Name;

            using (var sbc = new SqlBulkDelete(db))
            {
                return(sbc.BulkDelete(tableName, dt, pks[0]));
            }
        }