public static void Initialize(IServiceProvider serviceProvider) { using (var context = new MvcBooksContext( serviceProvider.GetRequiredService < DbContextOptions <MvcBooksContext> >())) { // Look for any movies. if (context.Book.Any()) { return; // DB has been seeded } context.Book.AddRange( new Book { Title = "Сияние", Author = "Стивен Кинг", ReleaseDate = DateTime.Parse("01-28-1977"), Price = 785 }, new Book { Title = "Зелёная миля", Author = "Стивен Кинг", ReleaseDate = DateTime.Parse("08-29-1996"), Price = 489 }, new Book { Title = "11/22/63", Author = "Стивен Кинг", ReleaseDate = DateTime.Parse("11-08-2011"), Price = 859 }, new Book { Title = "1408", Author = "Стивен Кинг", ReleaseDate = DateTime.Parse("11-01-1999"), Price = 641 } ); context.SaveChanges(); } }
public BooksController(MvcBooksContext context) { _context = context; }