// Update one existing department public static void UpdateDepartment() { using (EFO2MEntities context = new EFO2MEntities()) { Department department = new Department(); department.DepartmentID = 1; context.AttachTo("Department", department); department.Name = "Computer Engineering"; department.Course.Add(new Course() { CourseID = 2204, Title = "Arithmetic" }); try { Console.WriteLine("Modifying Department 1's Title to {0}" + ", and insert a new Course 2204 into the " + "Department 1", department.Name); context.SaveChanges(); Query(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
// Update one existing course public static void UpdateCourse() { using (EFO2MEntities context = new EFO2MEntities()) { Course course = new Course(); course.CourseID = 2203; context.AttachTo("Course", course); course.Title = "OOP"; try { Console.WriteLine("Modifying Course 2203's Title to {0}", course.Title); context.SaveChanges(); Query(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
// 更新一个现存的department public static void UpdateDepartment() { using (EFO2MEntities context = new EFO2MEntities()) { Department department = new Department(); department.DepartmentID = 1; context.AttachTo("Department", department); department.Name = "Computer Engineering"; department.Course.Add(new Course() { CourseID = 2204, Title = "Arithmetic" }); try { Console.WriteLine("Modifying Department 1's Title to {0}" + ", and insert a new Course 2204 into the " + "Department 1", department.Name); context.SaveChanges(); Query(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
// 更新一个现存的course public static void UpdateCourse() { using (EFO2MEntities context = new EFO2MEntities()) { Course course = new Course(); course.CourseID = 2203; context.AttachTo("Course", course); course.Title = "OOP"; try { Console.WriteLine("Modifying Course 2203's Title to {0}", course.Title); context.SaveChanges(); Query(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }