public PlantCategoriesControllerTest() { _dbOptions = new DbContextOptionsBuilder <PlantListingContext>() .UseInMemoryDatabase(databaseName: "in-memory plant categories") .Options; using (var dbContext = new PlantListingContext(_dbOptions)) { if (!dbContext.PlantCategories.Any()) { dbContext.PlantCategories.AddRange(PlantListingContextSeed.GetPreconfiguredPlantCategories()); } dbContext.SaveChanges(); } }
public void Configure(EntityTypeBuilder <PlantCategory> builder) { builder.ToTable("PlantCategory"); builder.HasKey(ci => ci.Id); builder.Property(ci => ci.Id) .UseHiLo("plant_category_hilo") .IsRequired(); builder.Property(cb => cb.Category) .IsRequired() .HasMaxLength(100); // To seed data builder.HasData(PlantListingContextSeed.GetPreconfiguredPlantCategories()); }
private void SeedDBContext(DbContextOptions <PlantListingContext> dbOptions) { using (var dbContext = new PlantListingContext(dbOptions)) { if (!dbContext.PlantCategories.Any()) { dbContext.PlantCategories.AddRange(PlantListingContextSeed.GetPreconfiguredPlantCategories()); } if (!dbContext.WeightUnits.Any()) { dbContext.WeightUnits.AddRange(PlantListingContextSeed.GetPreconfiguredWeightUnits()); } if (!dbContext.PlantDetails.Any()) { dbContext.PlantDetails.AddRange(PlantListingContextSeed.GetPreconfiguredPlantDetails()); } dbContext.SaveChanges(); } }