public static void Initialize(ShoppingListItemsDbContext context) { context.Database.EnsureCreated(); if (context.shoppinglistitems.Any()) { return; // DB has been seeded } var newshoppingitems = new ShoppingListItem[] { new ShoppingListItem() { name = "Bag of potatoes" }, new ShoppingListItem() { name = "Cookie dough" } }; foreach (ShoppingListItem i in newshoppingitems) { context.shoppinglistitems.Add(i); } context.SaveChanges(); }
public HomeController(ShoppingListItemsDbContext context) { _context = context; }