转自http://blog.csdn.net/winnyrain/article/details/51240684

Overcome SqlBulkCopy Limitations with C# Bulk Insw3school.com.cnert, Update, Delete and Merge

 
// Support all type of operations
var bulk = new BulkOperation(connection);
bulk.BulkInsert(dt);
bulk.BulkUpdate(dt);
bulk.BulkDelete(dt);
bulk.BulkMerge(dt); // Support List<T> and Lambda Mapping
var bulk = new BulkOperation<Customer>(connection);
bulk.ColumnInputExpression = c => new { c.Name, c.FirstName };
bulk.ColumnOutputExpression = c => c.CustomerID;
bulk.ColumnPrimaryKeyExpression = c => c.Code;
bulk.BulkMerge(customers);

High Performance Operations

Use scalable bulk operations (Bulk Insert, Update, Delete and Merge) and always 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 1,000 Rows 10,000 Rows 100,000 Rows 1,000,000 Rows
Insert 6 ms 25 ms 200 ms 2,000 ms
Update 50 ms 80 ms 575 ms 6,500 ms
Delete 45 ms 70 ms 625 ms 6,800 ms
Merge 65 ms 160 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.

// Output newly inserted identity value after an insert
bulk.ColumnMappings.Add("CustomerID", ColumnMappingDirectionType.Output); bulk.BulkInsert(dt);
// Support all type of operations
var bulk = new BulkOperation(connection);
bulk.BulkInsert(dt);
bulk.BulkUpdate(dt);
bulk.BulkDelete(dt);
bulk.BulkMerge(dt);
bulk.BulkSaveChanges(ds);
bulk.BulkSynchronize(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(long));
            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 < 100000; d++)
            {
               dt.Rows.Add(new object[] { null, DateTime.Now, d % 100, (d + 2) / (d + 1), (d + 3) / (d + 1), (d + 4) % 8 });
            }
            string ConnectionString = @"server=192.168.20.115\MSSQLSERVER2008;database=GPSTest;uid=test;pwd=test";             Stopwatch sw = new Stopwatch();
            using (DbConnection connection = new SqlConnection(ConnectionString))
            {                 connection.Open();
                sw.Start();
                var bulk = new BulkOperation(connection);
                //bulk.BulkInsert(dt);
                bulk.BulkUpdate(dt);
                //bulk.BulkDelete(dt);
                //bulk.BulkMerge(dt);
                //bulk.BulkSaveChanges(ds);
                //bulk.BulkSynchronize(dt);
                sw.Stop();
                Console.WriteLine("用时:" + sw.ElapsedMilliseconds.ToString());
                Console.Read();             }
        }
    }
}

C# Bulk Operations(转)的更多相关文章

  1. drupal7 Views Bulk Operations (VBO)

    介绍 drupal通常用views制作列表,列表也应该能实现某些操作,例如删除.审批等,并且应该是批量进行的,VBO的存在就是为了实现views批量操作功能.事实上,drupal把操作统称为actio ...

  2. bulk更新mongodb的脚本

    bulk批处理mongodb,比普通的js脚本来的更快一些. 官方网址:https://docs.mongodb.com/manual/reference/method/Bulk/ bulk支持的方法 ...

  3. Java使用实现面向对象编程:第七章集合框架的解读=>重中之重

    对于集合框架,是非常重要的知识,是程序员必须要知道的知识点. 但是我们为什么要引入集合框架呢? 我们之前用过数组存储数据,但是采用数组存储存在了很多的缺陷.而现在我们引用了集合框架,可以完全弥补了数组 ...

  4. ElasticSearch+Kibana 索引操作( 附源码)

    一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elastics ...

  5. jquery1.7.2的源码分析(二)

    jquery.extend jQuery.extend = jQuery.fn.extend = function () { var options, name, src, copy, copyIsA ...

  6. sql跨库查询

    ---------------------------------------------------------------------------------- --1. 创建链接服务器 --1. ...

  7. Backbone源码分析(三)

    Backbone源码分析(一) Backbone源码分析(二) Backbone中主要的业务逻辑位于Model和Collection,上一篇介绍了Backbone中的Model,这篇文章中将主要探讨C ...

  8. jQuery 2.0.3 源码分析 钩子机制 - 属性操作

    jQuery提供了一些快捷函数来对dom对象的属性进行存取操作. 这一部分还是比较简单的. 根据API这章主要是分解5个方法 .attr()   获取匹配的元素集合中的第一个元素的属性的值  或 设置 ...

  9. jQuery 3.0 的 setter/getter 模式

    jQuery 的 setter/getter 共用一个函数,通过是否传参来表明它是何种意义.简单说传参它是 setter,不传它是 getter. 一个函数具有多种意义在编程语言中并不罕见,比如函数重 ...

随机推荐

  1. Linux SVN 服务器

    一. SVN 简介 Subversion(SVN) 是一个开源的版本控制系統, 也就是说 Subversion 管理着随时间改变的数据. 这些数据放置在一个中央资料档案库 (repository) 中 ...

  2. FAX modem和传真协议简介

    FAX就是传真,传真通信是使用传真机,借助公用通信网或其他通信线路传送图片,文字等信息,并在接收方获得发送原件系统的副本的一种通信方式.传真通信是现代图像通信的重要组成部分,它是目前采用公用电话网传送 ...

  3. 如何搭建Packetbeat性能监控

    安装与配置JDK 1.  将jdk-8u111-linux-x64.tar.gz上传至Linux的/opt目录下,并执行解压命令: tar -zxvf jdk-8u111-linux-x64.tar. ...

  4. CodeFrist、ModelFirst、DatabaseFirst

    一.CodeFirst 使用System.Data.Entity.DbContext与System.Data.Entity.DbSet构建的数据模型,没有可视化文件但只有实体类的称为CodeFirst ...

  5. 数据库操作相关(sql语句-命令行)

    创建数据库: create database books; 创建用户: mysql> grant select,insert,delete,uptate     -> on books.* ...

  6. geotrellis使用(三十二)大量GeoTiff文件实时发布TMS服务

    前言 在上一篇文章中我讲了如何直接将Geotiff文件发布为TMS服务,在其中只讲了单幅Geotiff的操作,其实单幅这种量级的数据对Geotrellis来说就是杀鸡焉用牛刀,Geotrellis针对 ...

  7. Docker容器挂载宿主目录的情形分析

    Docker容器启动的时候,如果要挂载宿主机的一个目录,可以用-v参数指定. 譬如我要启动一个centos容器,宿主机的/test目录挂载到容器的/soft目录,可通过以下方式指定: # docker ...

  8. 力推:无限制下载神器aria2

    百度网盘是一个非常方便的存储以及寻找资源的好帮手,但是百度为了挣钱把非会员的下载网速一再限制(无力吐槽),还还好一直使用油猴插件加idm下载神器来下载百度云文件.奈何idm对bt种子文件不支持下载,终 ...

  9. 1.3tf的varible\labelencoder

    1.tf的varible变量 import tensorflow as tf #定义变量--这里是计数的变量 state=tf.Variable(0,name='counter') print (st ...

  10. Oracle安装部署之命令建库

    1.建目录: [oracle@wen ~]$ mkdir $ORACLE_BASE/admin/rezin/{a,b,c,dp}dump -p [oracle@wen ~]$ mkdir $ORACL ...