using System.Collections.Generic;
using System.Data.SqlClient;
public int CustomerID {get;set;}
public string CustomerName {get;set;}
public string ContactName {get;set;}
public string Address {get;set;}
public string City {get;set;}
public string PostalCode {get;set;}
public string Country {get;set;}
public static void Main()
DapperPlusManager.Entity<Customer>().Table("Customers")
.Identity(x => x.CustomerID);
var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer());
var customers = GenerateCustomers(5);
connection.BulkInsert(customers);
FiddleHelper.WriteTable("1 - Customers (After Insert):", connection.Query<Customer>("SELECT * FROM CUSTOMERS WHERE CustomerName LIKE 'Customer_%'"));
customers.Take(3).ToList().ForEach(x => x.CustomerName += "_Updated");
customers.AddRange(GenerateCustomers(3));
connection.BulkMerge(customers);
FiddleHelper.WriteTable("2 - Customers (After Merge):", connection.Query<Customer>("SELECT * FROM CUSTOMERS WHERE CustomerName LIKE 'Customer_%'"));
public static int Counter = 0;
public static List<Customer> GenerateCustomers(int count)
var customers = new List<Customer>();
for(;Counter < count; Counter++)
customers.Add(new Customer() { CustomerName = "CustomerName_" + Counter, ContactName = "ContactName_" + Counter, Address = "Address_" + Counter, City = "City_" + Counter, PostalCode = "PostalCode_" + Counter, Country = "Country_" + Counter});
public static void GenerateDatabase()
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
using (var command = connection.CreateCommand())
[CustomerID] [INT] IDENTITY(1,1) NOT NULL,
[CustomerName] [NVARCHAR](255) NULL,
[ContactName] [NVARCHAR](255) NULL,
[Address] [NVARCHAR](255) NULL,
[City] [NVARCHAR](255) NULL,
[PostalCode] [NVARCHAR](255) NULL,
[Country] [NVARCHAR](255) NULL,
CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED
command.ExecuteNonQuery();