private static void Initialize() { var initializer = new MigrateDatabaseToLatestVersion<Context, DbConfig>(); Database.SetInitializer(initializer); using (var context = new Context()) { context.Database.Initialize(force: true); context.SaveChanges(); } }
private static void ClearDb() { using (var context = new Context()) { foreach (var itinerary in context.Itineraries.ToList()) context.Itineraries.Remove(itinerary); foreach (var user in context.Users.Include(u => u.Address).ToList()) context.Users.Remove(user); context.SaveChanges(); } }
private static void InsertData() { var user = new User { Name = "John", Address = new Address { Street = "Victoria Avenue" } }; var itinerary = new Itinerary { Addresses = new List<Address> { user.Address } }; using (var context = new Context()) { context.Users.Add(user); context.Itineraries.Add(itinerary); context.SaveChanges(); } }