示例#1
0
        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(
                    new Movie
                {
                    Title    = "Tenet",
                    Category = "Action/Adventure",
                    Year     = 2020,
                    Director = "Christopher Nolan",
                    Rating   = "G",
                    Edited   = "n/a",
                    Notes    = "n/a",
                    Lent     = "n/a"
                }
                    );
                context.SaveChanges();
            }
        }
示例#2
0
 public EFMovieRepository(MovieDBContext context)
 {
     _context = context;
 }