public static void EnsurePopulated(IApplicationBuilder application) { MovieDbContext context = application.ApplicationServices.CreateScope().ServiceProvider.GetRequiredService <MovieDbContext>(); if (context.Database.GetPendingMigrations().Any()) { context.Database.Migrate(); } if (!context.Movies.Any()) { context.Movies.AddRange( //add in seed data new Movie { Title = "Batman", Category = "Action/Adventure", Year = 1989, Director = "Tim Burton", Rating = "PG-13", Notes = null, Lentto = null, Edited = false } ); context.SaveChanges(); } }
public void AddMovie(Movie movie) { _context.Movies.Add(movie); _context.SaveChanges(); }