Exemplo n.º 1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new WebAppContext(
                       serviceProvider.GetRequiredService <DbContextOptions <WebAppContext> >()))
            {
                if (context.Car.Any())
                {
                    return;   // Cars has been seeded
                }

                context.Car.AddRange(
                    new Car
                {
                    Brand = "VW",
                    Model = "Golf V",
                    Year  = 2007,
                    Hk    = 120,
                    Price = 270000
                },
                    new Car
                {
                    Brand = "Audi",
                    Model = "A6",
                    Year  = 2013,
                    Hk    = 220,
                    Price = 360000
                },
                    new Car
                {
                    Brand = "Ford",
                    Model = "Focus",
                    Year  = 2016,
                    Hk    = 170,
                    Price = 170000
                },
                    new Car
                {
                    Brand = "Jaguar",
                    Model = "XE",
                    Year  = 2017,
                    Hk    = 360,
                    Price = 400000
                },
                    new Car
                {
                    Brand = "Toyota",
                    Model = "Prius",
                    Year  = 2015,
                    Hk    = 90,
                    Price = 105000
                }


                    );
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new WebAppContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <WebAppContext> >()))
            {
                // Look for any movies.
                if (context.Movies.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movies.AddRange(
                    new Movie
                {
                    Title       = "When Harry Met Sally",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M
                },

                    new Movie
                {
                    Title       = "Ghostbusters ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = "Comedy",
                    Price       = 8.99M
                },

                    new Movie
                {
                    Title       = "Ghostbusters 2",
                    ReleaseDate = DateTime.Parse("1986-2-23"),
                    Genre       = "Comedy",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "King of Boys 2",
                    ReleaseDate = DateTime.Parse("2019-9-09"),
                    Genre       = "Tragy Comedy",
                    Price       = 7.92M
                },
                    new Movie
                {
                    Title       = "Rio Bravo",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M
                }
                    );
                context.SaveChanges();
            }
        }