Exemple #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var dbContext = new AppServiceDbContext(
                       serviceProvider.GetRequiredService <DbContextOptions <AppServiceDbContext> >()))
            {
                // Look for any superhero items.
                if (dbContext.Heroes.Any())
                {
                    return;   // DB has been seeded
                }

                PopulateTestData(dbContext);
            }
        }
Exemple #2
0
        public static void PopulateTestData(AppServiceDbContext dbContext)
        {
            foreach (var item in dbContext.Heroes)
            {
                dbContext.Remove(item);
            }

            dbContext.SaveChanges();
            dbContext.Heroes.Add(Esteban);
            dbContext.Heroes.Add(Ruben);
            dbContext.Heroes.Add(Javi);
            dbContext.Heroes.Add(Simo);
            dbContext.Heroes.Add(Virginia);
            dbContext.Heroes.Add(Alfons);

            dbContext.SaveChanges();
        }
 public EfRepository(AppServiceDbContext dbContext)
 {
     _dbContext = dbContext;
 }