// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { using (IServiceScope serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { AppDbContext context = serviceScope.ServiceProvider.GetService <AppDbContext>(); context.Database.Migrate(); int count = context.Products.Count(); if (count == 0) { Data.ProductsData productsData = new Data.ProductsData(); productsData.list.ForEach(async x => { await context.Products.AddAsync(x); }); context.SaveChanges(); } // CreateData(context); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseDefaultFiles(); app.UseStaticFiles(); app.UseSession(); app.UseMvc(); }
private async void CreateData(AppDbContext context) { int count = await context.Products.CountAsync(); if (count == 0) { Data.ProductsData productsData = new Data.ProductsData(); productsData.list.ForEach(async x => { await context.Products.AddAsync(x); }); context.SaveChanges(); } }