using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
public static void Main()
using (var context = new EntityContext())
context.Database.EnsureCreated();
var customers = new List<Customer>();
customers.Add(new Customer() { Name = "Carson", Type = 1, Description = "Updated_Description of Carson", IsActive = false });
customers.Add(new Customer() { Name = "Alexander", Type = 1, Description = "Description of Alexander", IsActive = false });
using (var context = new EntityContext())
context.BulkSynchronize(customers, options => {
options.ColumnPrimaryKeyExpression = customer => customer.Name;
options.SynchronizeDeleteDestinationTableFilterFormula = "DestinationTable.Type IN (1, 3)";
FiddleHelper.WriteTable("Update Customer 1; Remove Customer 2; Do nothing Customer 3; Delete Customer 4; Insert Customer_5",context.Customers.ToList());
public static void GenerateData()
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name = "Carson", Type = 1, Description = "Description of Carson", IsActive = true });
context.Customers.Add(new Customer() { Name = "Meredith", Type = 1, Description = "Description of Meredith", IsActive = true });
context.Customers.Add(new Customer() { Name = "Arturo", Type = 2, Description = "Description of Arturo", IsActive = true });
context.Customers.Add(new Customer() { Name = "Jonathan", Type = 3, Description = "Description of Jonathan", IsActive = true });
context.BulkSaveChanges();
FiddleHelper.WriteTable("Before BulkSynchronize",context.Customers.ToList());
public class EntityContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
public int Type { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Boolean IsActive { get; set; }