using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public static void Main()
using (var context = new EntityContext())
var list = context.Customers.ToList();
list.ForEach(x => x.Name += "_Synchronize" );
list.ForEach(x => x.IdentityInt += 100 );
list.Add( new Customer() { CustomerID = 3, IdentityInt = 4, Name ="Customer_C" });
context.BulkSynchronize(list, options => options.SynchronizeKeepidentity = true);
using (var context = new EntityContext())
FiddleHelper.WriteTable(context.Customers.ToList());
public static void GenerateData()
using (var context = new EntityContext())
context.Customers.Add(new Customer() { CustomerID = 1, Name ="Customer_A"});
context.Customers.Add(new Customer() { CustomerID = 2, Name ="Customer_B"});
context.BulkSaveChanges();
using (var context = new EntityContext())
FiddleHelper.WriteTable(context.Customers.ToList());
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdentityInt { get; set; }
public string Name { get; set; }