コード例 #1
0
ファイル: SeedData.cs プロジェクト: jhgranola/PizzaShop
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            PizzaShopDbContext context = app.ApplicationServices.GetRequiredService <PizzaShopDbContext>();

            //context.Database.Migrate();

            //PizzaShopDbContext context = services.GetRequiredService<PizzaShopDbContext>();

            if (!context.Products.Any())
            {
                context.Products.AddRange(
                    new Product {
                    Name = "Pepperoni Pizza", Price = 12.99M
                },
                    new Product {
                    Name = "Mushroom Pizza", Price = 10.99M
                },
                    new Product {
                    Name = "Sausage Pizza", Price = 13.99M
                }
                    );
                context.SaveChanges();
            }
        }
コード例 #2
0
 public EFProductRepository(PizzaShopDbContext ctx)
 {
     context = ctx;
 }