コード例 #1
0
ファイル: SeedData.cs プロジェクト: mariam-gogia/MovieRentals
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new HW6MovieSharingContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <HW6MovieSharingContext> >()))
            {
                // Check if there is any data
                if (context.Movie.Any())
                {
                    return; // DB has been seeded
                }

                // Create data
                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "Star Wars IV",
                    Category    = "Science Fiction",
                    IsShareable = true
                },
                    new Movie
                {
                    Title       = "The Matrix",
                    Category    = "Science Fiction",
                    IsShareable = true
                },
                    new Movie
                {
                    Title       = "The Social Network",
                    Category    = "Drama",
                    IsShareable = true
                },
                    new Movie
                {
                    Title       = "Star Trek First Contact",
                    Category    = "Science Fiction",
                    IsShareable = true
                },
                    new Movie
                {
                    Title       = "Captain Marvel",
                    Category    = "Adventure",
                    IsShareable = false,
                });;
                context.SaveChanges();
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BasePageModel"/> class.
 /// </summary>
 public BasePageModel(HW6MovieSharingContext context)
 {
     Context = context;
 }