/// <summary>
 /// Create a new Department object.
 /// </summary>
 /// <param name="departmentID">Initial value of the DepartmentID property.</param>
 public static Department CreateDepartment(global::System.Int32 departmentID)
 {
     Department department = new Department();
     department.DepartmentID = departmentID;
     return department;
 }
        /// <summary>
        /// Independent Association下插入一条新的Course和Department关联实体
        /// </summary>
        private static void InsertNewRelatedEntities()
        {
            using (IndependentAssociationEntities context =
                new IndependentAssociationEntities())
            {
                // 创建一个新的Department实体。
                Department department = new Department()
                {
                    DepartmentID = 6,
                    Name = "Software Engineering",
                    Budget = 300000,
                    StartDate = DateTime.Now
                };

                // 创建一个新的Course实体。
                Course course = new Course()
                {
                    CourseID = 6001,
                    Title = "Object Oriented",
                    Credits = 4,
                    StatusID = true,
                    // 设置导航属性。
                    Department = department
                };

                try
                {
                    // 注意: 只需要添加一个实体,因为关系和关联实体将自动被添加。
                    context.AddToCourses(course);

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Departments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDepartments(Department department)
 {
     base.AddObject("Departments", department);
 }