public static void DeleteCustomer(string customerId) { NorthwindEntities northwindEntities = new NorthwindEntities(); Customer customer = GetCustomerById(northwindEntities, customerId); if (customer == null) { return; } northwindEntities.Customers.Remove(customer); northwindEntities.SaveChanges(); Console.WriteLine("{0} deleted!", customerId); }
public static void TestSaveChanges() { NorthwindEntities firstDb = new NorthwindEntities(); NorthwindEntitiesTwin secondDb = new NorthwindEntitiesTwin(); Customer customer = firstDb.Customers.FirstOrDefault(p => p.CustomerID == "QUEEN"); Customer customer2 = secondDb.Customers.FirstOrDefault(p => p.CustomerID == "QUEEN"); customer.CompanyName = "ZXCVB"; customer2.CompanyName = "QWERT"; firstDb.SaveChanges(); secondDb.SaveChanges(); Console.WriteLine("ONLY THE SECOND CHANGE REMAINS SAVED"); Console.WriteLine("Maybe deny access to the second entity?"); }
public static void InsertCustomers(string customerID, string companyName, string contactName = null, string address = null, string city = null, string region = null, string postalCode = null, string country = null, string phone = null, string fax = null) { NorthwindEntities db = new NorthwindEntities(); Customer newCustomer = new Customer { CustomerID = customerID, CompanyName = companyName, ContactName = contactName, Address = address, City = city, Region = region, PostalCode = postalCode, Country = country, Phone = phone, Fax = fax }; if (GetCustomerById(db, customerID) != null) { return; } db.Customers.Add(newCustomer); db.SaveChanges(); }
public static void ModifyCustomer(string customerID, string newCompanyName) { NorthwindEntities northwindEntities = new NorthwindEntities(); Customer customer = GetCustomerById(northwindEntities, customerID); if (customer == null) { return; } customer.CompanyName = newCompanyName; northwindEntities.SaveChanges(); Console.WriteLine("{0} modified!", customerID); }