using System.Data.SqlClient;
using System.Collections.Generic;
public static void Main()
var customers = GenerateCustomers(5);
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
using (var bulk = new BulkOperation<Customer>(connection))
bulk.DestinationTableName = "Customers";
bulk.BulkInsert(customers);
FiddleHelper.WriteTable("1 - Without identity",customers);
using (var bulk = new BulkOperation<Customer>(connection))
bulk.DestinationTableName = "Customers";
bulk.AutoMapOutputIdentity = true;
bulk.BulkInsert(customers);
FiddleHelper.WriteTable("2 - With identity", customers);
public static List<Customer> GenerateCustomers(int count)
List<Customer> list = new List<Customer>();
for(int i = 0; i < count; i++)
list.Add(new Customer() { Name = "Customer_" + i});
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; }