private void AddEmployee() { using (EmployeeDataContext context = new EmployeeDataContext(App.ConnectionString)) { var department = this.lstDepartment.SelectedItem as Department; var contextualDepartment = context.Departments.FirstOrDefault(e => e.Id == department.Id); Employee emp = new Employee { EName = this.txtName.Text, Age = Convert.ToInt32(this.txtAge.Text), Department = contextualDepartment }; context.Employees.InsertOnSubmit(emp); context.SubmitChanges(); } }
private void detach_Employee(Employee emp) { emp.Department = null; }
private void attach_Employee(Employee emp) { emp.Department = this; }