Beispiel #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new CoffeeMugAppContext(
                       serviceProvider.GetRequiredService <DbContextOptions <CoffeeMugAppContext> >()
                       ))
            {
                if (context.Product.Any())
                {
                    return;         //Database has been seeded
                }

                context.Product.AddRange(
                    new Product
                {
                    Name  = "Box of cookies",
                    Price = 2.00M
                },
                    new Product
                {
                    Name  = "Frozen pizza",
                    Price = 8.00M
                },
                    new Product
                {
                    Name  = "Pasta",
                    Price = 3.00M
                },
                    new Product
                {
                    Name  = "Hamburger",
                    Price = 5.00M
                },
                    new Product
                {
                    Name  = "Bubblegum",
                    Price = 1.00M
                }
                    );
                context.SaveChanges();
            }
        }
 public ProductController(CoffeeMugAppContext context)
 {
     _context = context;
 }