static void InsertOrder( string shipName, string shipAddress, string shipCity, string shipRegionm, string shipPostalCode, string shipCountry, string customerID = null, int? employeeID = null, DateTime? orderDate = null, DateTime? requiredDate = null, DateTime? shippedDate = null, int? shipVia = null, decimal? freight = null) { using (NorthwindEntities context = new NorthwindEntities()) { Order newOrder = new Order { ShipAddress = shipAddress, ShipCity = shipCity, ShipCountry = shipCountry, ShipName = shipName, ShippedDate = shippedDate, ShipPostalCode = shipPostalCode, ShipRegion = shipRegionm, ShipVia = shipVia, EmployeeID = employeeID, OrderDate = orderDate, RequiredDate = requiredDate, Freight = freight, CustomerID = customerID }; context.Orders.Add(newOrder); context.SaveChanges(); Console.WriteLine("Row is inserted."); } }
public static void RemoveCustomerByID(NorthwindEntities db, string customerID) { var customerForRemove = db.Customers.Where(c => c.CustomerID == customerID).First(); db.Customers.Remove(customerForRemove); db.SaveChanges(); }
public static void ModifyCustomerByID(NorthwindEntities db, string customerID, string newCompanyName, string newContactName) { var customerForUpdate = db.Customers.Where(c => c.CustomerID == customerID).First(); customerForUpdate.CompanyName = newCompanyName; customerForUpdate.ContactName = newContactName; db.SaveChanges(); }
public static void CreateNewCustomer(NorthwindEntities db, string customerID, string companyName, string contactName, string country) { var newCustomer = new Customer() { CustomerID = customerID, CompanyName = companyName, ContactName = contactName, Country = country }; db.Customers.Add(newCustomer); db.SaveChanges(); }
static void Main(string[] args) { using (NorthwindEntities northwindEntities1 = new NorthwindEntities()) { using (NorthwindEntities northwindEntities2 = new NorthwindEntities()) { Customer customerByFirstDataContext = northwindEntities1.Customers.Find("CHOPS"); customerByFirstDataContext.Region = "SW"; Customer customerBySecondDataContext = northwindEntities2.Customers.Find("CHOPS"); customerBySecondDataContext.Region = "SSWW"; northwindEntities1.SaveChanges(); northwindEntities2.SaveChanges(); } } Console.WriteLine("Changes successfully made!"); }