using System.Collections.Generic;
using System.Data.SqlClient;
public static void Main()
var customers = GenerateCustomers(3);
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
ShowData(connection, "Before");
using (var bulk = new BulkOperation<Customer>(connection))
bulk.DestinationTableName = "Customers";
bulk.BulkUpdate(customers);
ShowData(connection, "After");
public static void ShowData(SqlConnection connection, string text)
using (var command = connection.CreateCommand())
var sqlDataAdapter = new SqlDataAdapter(command);
ds.Tables[0].TableName = "1 - Customers " + text;
FiddleHelper.WriteTable(ds.Tables[0]);
public static List<Customer> GenerateCustomers(int count, bool useOld = false)
List<Customer> list = new List<Customer>();
for(int i = 0; i < count; i++)
list.Add(new Customer() { CustomerID = (i + 1), Name = (useOld ? "Old_" : "") + "Customer_" + i});
public static void SeedCustomers(int count)
var customers = GenerateCustomers(count, true);
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
using (var bulk = new BulkOperation<Customer>(connection))
bulk.DestinationTableName = "Customers";
bulk.BulkInsert(customers);
public static void GenerateDatabase()
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
using (var command = connection.CreateCommand())
[CustomerID] [INT] IDENTITY(1,1) NOT NULL,
[Name] [NVARCHAR](MAX) NULL,
CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED
command.ExecuteNonQuery();
public int CustomerID { get; set; }
public string Name { get; set; }