using System.Data.Entity;
public static void Main()
using (var context = new EntityContext())
var customers = context.Customers.ToList();
customers.ForEach(x => { x.Name += "_Updated"; x.Description += "_Updated"; x.ModifiedDate = DateTime.Now; x.IsActive = false; });
customers.Last().CreatedDate = DateTime.Now;
context.BulkUpdate(customers, options =>
options.IgnoreOnUpdateMatchedAndConditionExpression = c => new {c.Name, c.Description, c.ModifiedDate, c.IsActive };
using (var context = new EntityContext())
FiddleHelper.WriteTable("After BulkUpdate",context.Customers.ToList());
public static void GenerateData()
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name = "Carson", Description = "Description of Carson", CreatedDate = DateTime.Now.AddDays(-3), ModifiedDate = DateTime.Now.AddDays(-3), IsActive = true });
context.Customers.Add(new Customer() { Name = "Meredith", Description = "Description of Meredith", CreatedDate = DateTime.Now.AddDays(-2), ModifiedDate = DateTime.Now.AddDays(-2), IsActive = true });
context.Customers.Add(new Customer() { Name = "Arturo", Description = "Description of Arturo", CreatedDate = DateTime.Now.AddDays(-1), ModifiedDate = DateTime.Now.AddDays(-2), IsActive = true });
context.BulkSaveChanges();
FiddleHelper.WriteTable("Before BulkUpdate",context.Customers.ToList());
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 DateTime? ModifiedDate { get; set; }
public DateTime CreatedDate { get; set; }
public Boolean IsActive { get; set; }