using System.Collections.Generic;
using System.Data.Entity;
class CustComp : Customer {
public static void Main()
using (var context = new EntityContext())
var list = context.Customers.ToList();
list.Add(new Customer() { Name ="Customer_C", Description = "Description"});
list.First().Description = "Updated_A";
FiddleHelper.WriteTable(context.Customers.ToList());
var customers = new List<Customer>();
customers.Add(new Customer() { Name = "Customer_B", Description = "Updated_B", IsActive = false});
customers.Add(new Customer() { Name = "Customer_D", Description = "Description", IsActive = false});
using (var context = new EntityContext())
context.BulkMerge(customers, options => options.ColumnPrimaryKeyExpression = customer => customer.Name);
FiddleHelper.WriteTable(context.Customers.ToList());
public static void GenerateData()
var custList = new List<Customer>()
new CustComp() { Name ="Customer_A", Description = "Description", IsActive = true, C1 = new C1() { S1 = "Test1" } },
new CustComp() { Name ="Customer_B", Description = "Description", IsActive = true, C1 = new C1() { S1 = "Test2" } }
using (var context = new EntityContext())
context.Customers.AddRange(custList);
context.BulkSaveChanges();
FiddleHelper.Dump((custList[0] as CustComp).C1);
using (var context = new EntityContext())
FiddleHelper.WriteTable(custList);
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; }