public EFStoreRepository(StoreDbcontext ctx) { context = ctx; }
public static void EnsurePopulated(IApplicationBuilder app) { StoreDbcontext context = app.ApplicationServices .CreateScope().ServiceProvider.GetRequiredService <StoreDbcontext>(); if (context.Database.GetPendingMigrations().Any()) { context.Database.Migrate(); } if (!context.Products.Any()) { context.Products.AddRange( new Product { Name = "Kayak", Decription = "A boat for one person", Category = "Watersports", Price = 275 }, new Product { Name = "Lifejacket", Decription = "Protective and fashionable", Category = "Watersports", Price = 48.95m }, new Product { Name = "Soccer Ball", Decription = "FIFA-approved size and weight", Category = "Soccer", Price = 19.50m }, new Product { Name = "Corner Flags", Decription = "Give your playing field a professional touch", Category = "Soccer", Price = 34.95m }, new Product { Name = "Stadium", Decription = "Flat-packed 35,000-seat stadium", Category = "Soccer", Price = 79500 }, new Product { Name = "Thinking Cap", Decription = "Improve brain efficiency by 75%", Category = "Chess", Price = 16 }, new Product { Name = "Unsteady Chair", Decription = "Secretly give your opponent a disadvantage", Category = "Chess", Price = 29.95m }, new Product { Name = "Human Chess Board", Decription = "A fun game for the family", Category = "Chess", Price = 75 }, new Product { Name = "Bling-Bling King", Decription = "Gold-plated, diamond-studded King", Category = "Chess", Price = 1200 } ); context.SaveChanges(); } }