/// <summary> /// 批量插入,不建议使用List插入、性能会受一定影响 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context">当前DbContext</param> /// <param name="tableName">要插入的表名称</param> /// <param name="list">List列明必须与数据表列一致,严格大小写区分</param> public static int BulkInsert <T>(this SqlServerDbContext context, string tableName, IList <T> list) { var provider = new BulkInsertSqlServerProvider(context); var result = provider.BulkInsert(tableName, list); return(result); }
/// <summary> /// 批量插入 /// </summary> /// <param name="context">当前DbContext</param> /// <param name="tableName">要插入的表名称</param> /// <param name="dataTable">DataTable</param> public static int BulkInsert(this SqlServerDbContext context, string tableName, DataTable dataTable) { var provider = new BulkInsertSqlServerProvider(context); var result = provider.BulkInsert(tableName, dataTable); return(result); }
/// <summary> /// 批量插入(SqlServer) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="destinationTableName"></param> /// <param name="list">List列明必须与数据表列一致,严格大小写区分</param> /// <param name="batchSize"></param> public static void BulkInsertSqlBulkCopy <T>(this SqlServerDbContext context, string destinationTableName, IEnumerable <T> list, SqlBulkCopyOptions options, int batchSize = DefaultBatchSize) where T : class { var provider = new BulkInsertSqlServerProvider(context); var table = list.ToDataTable(); BulkInsert(context, table, destinationTableName, options, batchSize); }