public static void InsertCustomer(string customerId, string companyName, string city) { NorthwindEntities connection = new NorthwindEntities(); using (connection) { var newCustomer = new Customer { CustomerID = customerId, CompanyName = companyName, ContactName = null, ContactTitle = null, Address = null, City = city, Region = null, PostalCode = null, Country = null, Phone = null, Fax = null }; connection.Customers.Add(newCustomer); connection.SaveChanges(); } }
public static void ModifyCustomer(string customerId, string companyName, string city) { NorthwindEntities connection = new NorthwindEntities(); using (connection) { var customerToModify = connection.Customers.Find(customerId); customerToModify.CompanyName = companyName; customerToModify.City = city; connection.SaveChanges(); } }
public static void DeleteCustomer(string customerId) { NorthwindEntities connection = new NorthwindEntities(); using (connection) { var customerToRemove = connection.Customers.Find(customerId); connection.Customers.Remove(customerToRemove); connection.SaveChanges(); } }
private static void Main() { var firstEntity = new NorthwindEntities(); var secondEntity = new NorthwindEntities(); using (firstEntity) { using (secondEntity) { var first = firstEntity.Customers.Find("ALFKI"); first.Region = "RE"; var second = secondEntity.Customers.Find("ALFKI"); second.Region = "ER"; firstEntity.SaveChanges(); secondEntity.SaveChanges(); } } Console.WriteLine("Done"); }