public static void EnsurePopulated(IApplicationBuilder app) { HangmanDbContext context = app.ApplicationServices .CreateScope().ServiceProvider.GetRequiredService <HangmanDbContext>(); if (context.Database.GetPendingMigrations().Any()) { context.Database.Migrate(); } if (!context.Questions.Any()) { context.Questions.AddRange( new Question { Title = "abruptly" }, new Question { Title = "awkward" }, new Question { Title = "numbskull" }, new Question { Title = "voyeurism" }, new Question { Title = "pneumonia" }, new Question { Title = "transgress" }, new Question { Title = "wristwatch" }, new Question { Title = "thumbscrew" }, new Question { Title = "espionage" }, new Question { Title = "mnemonic" }); context.SaveChanges(); } }
public HangmanRepository(HangmanDbContext ctx) { context = ctx; }