protected override void Seed(InheritanceContext context) { base.Seed(context); ChangesDate = new DateTime(2010, 1, 1); context.RemoveRange(context.ChangeTracker.Entries().Where(e => e.Entity is Animal).Select(e => e.Entity)); context.RemoveRange(context.ChangeTracker.Entries().Where(e => e.Entity is Plant).Select(e => e.Entity)); context.RemoveRange(context.ChangeTracker.Entries().Where(e => e.Entity is Country).Select(e => e.Entity)); context.RemoveRange(context.ChangeTracker.Entries().Where(e => e.Entity is Drink).Select(e => e.Entity)); context.SaveChanges(); var tableNames = new List <string> { "Animals", "Plants", "Countries", "Drinks" }; foreach (var tableName in tableNames) { context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] SET (SYSTEM_VERSIONING = OFF)"); context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] DROP PERIOD FOR SYSTEM_TIME"); context.Database.ExecuteSqlRaw($"UPDATE [{tableName + "History"}] SET PeriodStart = '2000-01-01T01:00:00.0000000Z'"); context.Database.ExecuteSqlRaw($"UPDATE [{tableName + "History"}] SET PeriodEnd = '2020-07-01T07:00:00.0000000Z'"); context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] ADD PERIOD FOR SYSTEM_TIME ([PeriodStart], [PeriodEnd])"); context.Database.ExecuteSqlRaw($"ALTER TABLE [{tableName}] SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[{tableName + "History"}]))"); } }
protected void SeedData(InheritanceContext context) { var kiwi = new Kiwi { Species = "Apteryx haastii", Name = "Great spotted kiwi", IsFlightless = true, FoundOn = Island.South }; var eagle = new Eagle { Species = "Aquila chrysaetos canadensis", Name = "American golden eagle", Group = EagleGroup.Booted }; eagle.Prey.Add(kiwi); var rose = new Rose { Species = "Rosa canina", Name = "Dog-rose", HasThorns = true }; var daisy = new Daisy { Species = "Bellis perennis", Name = "Common daisy" }; var nz = new Country { Id = 1, Name = "New Zealand" }; nz.Animals.Add(kiwi); var usa = new Country { Id = 2, Name = "USA" }; usa.Animals.Add(eagle); context.Set <Animal>().Add(kiwi); context.Set <Bird>().Add(eagle); context.Set <Country>().Add(nz); context.Set <Country>().Add(usa); context.Set <Rose>().Add(rose); context.Set <Daisy>().Add(daisy); context.SaveChanges(); }
public static void Seed(InheritanceContext context) { var animals = InheritanceData.CreateAnimals(); var countries = InheritanceData.CreateCountries(); var drinks = InheritanceData.CreateDrinks(); var plants = InheritanceData.CreatePlants(); InheritanceData.WireUp(animals, countries); context.Animals.AddRange(animals); context.Countries.AddRange(countries); context.Drinks.AddRange(drinks); context.Plants.AddRange(plants); context.SaveChanges(); }