public static void Initialise(IServiceProvider sp) { using (var context = new ETZContext(sp.GetRequiredService <DbContextOptions <ETZContext> >())) { if (!context.Locations.Any()) { context.Locations.AddRange( new Location { Id = 1, Name = "Glasgow" }, new Location { Id = 2, Name = "London" }, new Location { Id = 3, Name = "Sydney" } ); context.SaveChanges(); } if (!context.People.Any()) { context.People.AddRange( new Person { Id = 1, Name = "Mr Peter Smith", Sex = Gender.Male, DOB = DateTime.Parse("22/05/1974"), Position = "Account Executive", LocationId = 2, Age = 44 }, new Person { Id = 2, Name = "Mr Simon Dreyfus", Sex = Gender.Male, DOB = DateTime.Parse("01/03/1982"), Position = "Business Analyst", LocationId = 3, Age = 36 }, new Person { Id = 3, Name = "Mrs Sally Elfish", Sex = Gender.Female, DOB = DateTime.Parse("15/09/1980"), Position = "Risk Manager", LocationId = 2, Age = 37 }, new Person { Id = 4, Name = "Miss Lisa Morrow", Sex = Gender.Female, DOB = DateTime.Parse("29/01/1970"), Position = "Business Manager", LocationId = 1, Age = 48 }, new Person { Id = 5, Name = "Dr Chris Ellis", Sex = Gender.Male, DOB = DateTime.Parse("23/02/1986"), Position = "Account Executive", LocationId = 2, Age = 32 } ); context.SaveChanges(); } } }
public DbService(ETZContext context) => _context = context;