using System.Data.Entity;
using System.Collections.Generic;
public static void Main()
using (var context = new EntityContext())
context.Database.Log = Console.Write;
using (DbContextTransaction transaction = context.Database.BeginTransaction())
List<Customer> customerList = new List<Customer>()
new Customer() { Name ="John"},
new Customer() { Name ="Andy"},
new Customer() { Name ="Mark"}
context.Customers.AddRange(customerList);
context.Invoices.Add(new Invoice() { Date = DateTime.Now.AddDays(-107), CustomerID = 1});
Console.WriteLine("Error occurred.");
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Customer> Customers { get; set; }
public DbSet<Invoice> Invoices { get; set; }
public int CustomerID { get; set; }
public string Name { get; set; }
public virtual List<Invoice> Invoices { get; set; }
public int InvoiceID { get; set; }
public DateTime Date { get; set; }
public int CustomerID { get; set; }
public virtual Customer Customer { get; set; }
public virtual ICollection<Item> Items { get; set; }
public int ItemID { get; set; }
public string Name { get; set; }
public int InvoiceID { get; set; }
public virtual Invoice Invoice { get; set; }