using System.Collections.Generic;
using System.Data.Entity;
public static void Main()
using (var context = new EntityContext())
var customers = GenerateCustomers(5);
FiddleHelper.WriteTable("1 - Before", context.Customers.ToList());
context.BulkDelete(customers);
FiddleHelper.WriteTable("2 - After", context.Customers.ToList());
using(var context = new EntityContext())
var customers = GenerateCustomers(5);
FiddleHelper.WriteTable("3 - Before", context.Customers.ToList());
context.BulkDelete(customers, options => options.ColumnPrimaryKeyExpression = customer => customer.Code);
FiddleHelper.WriteTable("4 - After", context.Customers.ToList());
public static List<Customer> GenerateCustomers(int count)
var list = new List<Customer>();
for(int i = 0; i < count; i++)
list.Add(new Customer() { Code = "Code_" + i, FirstName = "FirstName_" + i, LastName = "LastName_" + i });
using (var context = new EntityContext())
context.BulkInsert(list);
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
public string Code { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }