zzzprojects / Bulk-Operations

C# SQL Bulk Operations | High-performance C# bulk insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL, and SQLite.
https://bulk-operations.net
142 stars 34 forks source link

BulkInsert And BulkDelete ? #45

Closed zhanfuzhi closed 5 years ago

zhanfuzhi commented 5 years ago

How to batch two tables at the same time

using (var connection = new SqlConnection(connectionString)) { connection.Open();

                        // BulkInsert
                        using (var bulk = new BulkOperation<Task01Rec>(connection))
                        {
                            bulk.DestinationTableName = "Task_01_Rec_History";
                            bulk.AutoMapOutputDirection = false; // performance can be improved with options

                            bulk.BulkInsert(tasklist.ToList<Task01Rec>());

                            bulk.BulkDelete(systasklist.ToList<sysTask>());

                        }
                    }
JonathanMagnan commented 5 years ago

Hello @zhanfuzhi ,

You currently cannot, you need to use a transaction if you want both be committed at the same time.

Let me know if that answer correctly to your question.

Best Regards,

Jonathan