private static void InsertCustomers() { using (var context = new OnlineStoreContext()) { context.Customers.Add(new Customer() { Name = "Sheva" }); context.Add(new Customer() { Name = "Albet" }); context.AddRange(new[] { new Customer() { Name = "Masha" }, new Customer() { Name = "Dasha" } }); context.SaveChanges(); //Faster if you use bulkcopy(tempTable) //Console.WriteLine($"{customer.Name }{customer.Id }"); } }
private static void InsertProducts() { using (var context = new OnlineStoreContext()) { context.Add(new Product() { Name = "IPhone X", Price = 100 }); context.AddRange(new[] { new Product() { Name = "MacBook Pro", Price = 100 }, new Product() { Name = "IWatch", Price = 200 } }); context.SaveChanges(); } }
private static void CreateOrder(string customerName, List <OrderItem> orederItems) { using (var context = new OnlineStoreContext()) { context.Add(new Order() { Customer = context.Customers.Where(x => x.Name == customerName).FirstOrDefault(), OrderDate = DateTimeOffset.Now, Discount = 0, OrderItems = new List <OrderItem>() { new OrderItem() { Product = new Product() { Name = "SamsungTV", Price = 20000 } } } }); } }