public static void Seed(ShoppingCartContext shoppingCartContext) { if (!shoppingCartContext.ShoppingCartItems.Any()) { var shoppingCarts = new List <ShoppingCart> { new ShoppingCart { UserName = "******", Items = new List <ShoppingCartItem> { new ShoppingCartItem { Color = "Red", Quantity = 3, Price = 899, ProductId = 1, ProductName = "Product", } } } }; shoppingCartContext.ShoppingCarts.AddRange(shoppingCarts); shoppingCartContext.SaveChanges(); } }
public static void SeedAsync(ShoppingCartContext shoppingCartContext) { if (!shoppingCartContext.ShoppingCart.Any()) { var shoppingCarts = new List <ShoppingCart> { new ShoppingCart { UserName = "******", Items = new List <ShoppingCartItem> { new ShoppingCartItem { Quantity = 2, Color = "Black", Price = 699, ProductId = 1, ProductName = "Mi10T" }, new ShoppingCartItem { Quantity = 3, Color = "Red", Price = 899, ProductId = 2, ProductName = "P40" } } } }; shoppingCartContext.ShoppingCart.AddRange(shoppingCarts); shoppingCartContext.SaveChanges(); } }