Esempio n. 1
0
        public WeightUnitsControllerTest()
        {
            _dbOptions = new DbContextOptionsBuilder <PlantListingContext>()
                         .UseInMemoryDatabase(databaseName: "in-memory weight units")
                         .Options;

            using (var dbContext = new PlantListingContext(_dbOptions))
            {
                if (!dbContext.WeightUnits.Any())
                {
                    dbContext.WeightUnits.AddRange(PlantListingContextSeed.GetPreconfiguredWeightUnits());
                }

                dbContext.SaveChanges();
            }
        }
Esempio n. 2
0
        public void Configure(EntityTypeBuilder <WeightUnit> builder)
        {
            builder.ToTable("WeightUnit");

            builder.HasKey(ci => ci.Id);

            builder.Property(ci => ci.Id)
            .UseHiLo("weight_unit_hilo")
            .IsRequired();

            builder.Property(cb => cb.Unit)
            .IsRequired()
            .HasMaxLength(50);

            // To seed data
            builder.HasData(PlantListingContextSeed.GetPreconfiguredWeightUnits());
        }
        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();
            }
        }