Go from http://blog.csdn.net/winnyrain/article/details/51240684Overcome SqlBulkCopy limitations with C # Bulk Insw3school.com.cnert, Update, Delete and Merge
Support all type of operationsVarBulk=NewBulkoperation(Connection);Bulk.Bulkinsert(Dt);Bulk.Bulkupdate(Dt);Bulk.Bulkdelete(Dt);Bulk.Bulkmerge(Dt);Support List<t> and Lambda MappingVarBulk=NewBulkoperation<Customer> (Connection);Bulk.Columninputexpression=C=new {c. Namec. FirstName }; bulk. Columnoutputexpression = c => c . customerid; Bulk. Columnprimarykeyexpression = c => c code; Bulk. (customers
High Performance Operations
Use Scalable Bulk operations (bulk Insert, Update, Delete and Merge) and all get the best performance available For your database provider.
- SQL Server 2008+
- SQL Azure
- SQL Compact
- Mysql
- Sqlite
- PostgreSQL (Coming soon)
- Oracle (Coming soon)
| Operations | $
Rows |
Rows |
100,000 Rows |
1,000,000 Rows |
| Insert |
6 ms |
Ms |
Ms |
2,000 ms |
| Update |
Ms |
Ms |
575 ms |
6,500 ms |
| Delete |
Ms |
Ms |
625 ms |
6,800 MS |
| Merge |
Ms |
Ms |
1,200 ms |
12,000 MS |
* Benchmark for SQL Server
Output Identity Value
Overcome SqlBulkCopy limitations and use flexible features to output inserted identity and concurrency column values.< /c0>
// Output newly inserted identity value after an insertbulk.ColumnMappings.Add("CustomerID", ColumnMappingDirectionType.Output);bulk.BulkInsert(dt);
Support all type of operationsVarBulk=NewBulkoperation(Connection); bulk. Bulkinsert (dt. (dt. (dt. (dt. (ds. (dt
Reference:
http://bulk-operations.net/
http://www.zzzprojects.com/
Examples:
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Using system.data;using system.data.sqlclient;using system.data.common;using system.diagnostics;using Z. Bulkoperations;using z.data.sqlclient;namespace bulktest{ class program { static void Main (string[] args) { DataTable DT = new DataTable (); DT. TableName = "Obddata"; DataColumn column = new DataColumn ("Serviceid", typeof (Lon g); column. AutoIncrement = true; DT. Columns.Add (column); DT. Columns.Add (New DataColumn ("Gpstime", typeof (DateTime))); DT. Columns.Add (New DataColumn ("Lat", typeof (Decimal))); DT. Columns.Add (New DataColumn ("LNG", typeof (Decimal)); DT. Columns.Add (New DataColumn ("Speed", typeof (Decimal))); DT. Columns.Add (New DataColumn ("Altitude", typeof (int))); for (int d = 0; d < 1000 00; d++) { &NBSP;DT. Rows.Add (new object[] {null, DateTime.Now, d%, (D + 2)/(d + 1), (d + 3)/(d + 1), (D + 4)% 8}); &N Bsp } String ConnectionString = @ "Server=192.168.20.115\mssqlser Ver2008;database=gpstest;uid=test;pwd=test "; Stopwatch SW = new Stopwatch (); nbsp using (DbConnection connection = new SqlConnection (ConnectionString)) &NBS P { connection. Open (); SW. Start (); var bulk = new Bulkoperation (connection); &NB Sp //bulk. Bulkinsert (DT); bulk. Bulkupdate (DT); //bulk. Bulkdelete (DT); //bulk. Bulkmerge (DT); //bulk. Bulksavechanges (DS); //bulk. Bulksynchronize (DT); SW. Stop (); Console.WriteLine ("Spents:" + SW. Elapsedmilliseconds.tostring ()); Console.read (); & nbsp } &NBSP } }}
C # Bulk Operations (GO)