using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public static void Main()
List<Customer> list1 = new List<Customer>() { new Customer() { Name ="Customer_A", Description = "Description" , IsActive = false },
new Customer() { Name ="Customer_B", Description = "Description", IsActive = true },
new Customer() { Name ="Customer_C", Description = "Description" , IsActive = true }};
List<Customer> list2 = new List<Customer>() { new Customer() { Name ="Customer_A", Description = "Description_Updated" , IsActive = false },
new Customer() { Name ="Customer_B", Description = "Description_Updated", IsActive = true },
new Customer() { Name ="Customer_C", Description = "Description_Updated" , IsActive = true }};
using (var context = new EntityContext())
context.BulkInsert(list1, options => {
options.ColumnPrimaryKeyExpression = e => e.Name;
options.AllowDuplicateKeys = true;
options.IncludeGraph = true;
FiddleHelper.WriteTable("Table 1",list1);
using (var context = new EntityContext())
context.BulkMerge(list2, options => {
options.IncludeGraph = true;
options.IncludeGraphOperationBuilder = buidler => {
options.ColumnPrimaryKeyExpression = e => e.Name;
options.AllowDuplicateKeys = true;
FiddleHelper.WriteTable("Table 2",list2);
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Boolean IsActive { get; set; }