Ejemplo n.º 1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var db = new ProductDbContext(
                       serviceProvider.GetRequiredService <DbContextOptions <ProductDbContext> >()))
            {
                // Look for any board games.
                if (db.Product.Any())
                {
                    return;   // Data was already seeded
                }

                db.Product.AddRange(
                    new Product
                {
                    Name  = "Candy Land",
                    Price = 4.50f
                },
                    new Product
                {
                    Name  = "Godzilla",
                    Price = 3.25f
                },
                    new Product
                {
                    Name  = "PowerRangers",
                    Price = 7.50f
                },
                    new Product
                {
                    Name  = "The Sims",
                    Price = 5f
                },
                    new Product
                {
                    Name  = "Alien",
                    Price = 10f
                },
                    new Product
                {
                    Name  = "Predator",
                    Price = 8.75f
                });

                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 public ProductService(ProductDbContext context)
 {
     db = context;
 }