更新代码中的多个表关系

时间:2016-08-26 00:40:43

标签: asp.net-mvc linq-to-sql linq-to-entities

我需要在三个表之间更新多对多关系。

员工和课程以及员工课程。

当表employeecourse中的更新课程ID未完成时。

我的模型customemployee2:

namespace WebCourse.Models {
  public class Customemployee2
   {
      public string Name { get; set; }
        public int Salary { get; set; }
        public string Email { get; set; }
     public int  DistrictId { get; set; }

      public int CourseId { get; set; }
      public IEnumerable<SelectListItem> Districts { set; get; }

        public List<EmployeeCourse> Courses { get; set; }
        public List<EmployeeLangage> Langs { get; set; }
    } }



 [HttpPost]
        public ActionResult Edit(int id,Customemployee2 cust2)
        {
            Employee old = db.Employees.Find(id);
            if (old != null)
            {
                old.Name = cust2.Name;
                old.Email = cust2.Email;
                old.DistrictId = cust2.DistrictId;
                old.Salary = cust2.Salary;
               //what i write here to update relation in employeecourse where select course id

                db.SaveChanges();
                return RedirectToAction("Index");
                db.Employees.Include


            }
            return View(cust2);
        }

如何更新表employeecourse中的courseid?

0 个答案:

没有答案