private static void DeleteCustomer(string name) { var customer = _context.Customers.FirstOrDefault(x => x.Name == name); if (customer != null) { _context.Customers.Remove(customer); _context.SaveChanges(); } //_context.Database.ExecuteSqlRaw("DELETE FROM dbo.Customer WHERE Id = 0, 15"); }
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 QueryAndUpdateProductDisconnected() { var product = _context.Products.First(); product.Price *= 1.1M; //_context.Products.Update(product); using (var newContext = new OnlineStoreContext()) { newContext.Products.Update(product); newContext.SaveChanges(); } }
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(); } }