public static void EnsureSeedData(this PersonDbContext db) { if (!db.People.Any()) { db.People.Add(new Person { FirstName = "Ashwin", LastName = "Kumar", Age = 37, Gender = Gender.Male }); db.SaveChanges(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, PersonDbContext db) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); db.EnsureSeedData(); }