标签:
using (DataContext dbcontext=new DataContext ())
{
//emp.department.ID = dep.ID;
//emp.department = dep;
/*foreach (var item in dep.employees)
{
item.department.ID = dep.ID;
dbcontext.employees.Add(item);
dbcontext.SaveChanges();
}*/
int did = dep.ID;
Department dep1 = new Department();
dep1 = dbcontext.dempartments.Find(did);
Employee emp1 = new Employee();
emp1 = emp;
emp1.department = dep1;
dbcontext.employees.Add(emp1);
dbcontext.SaveChanges();
return RedirectToAction("List");
}
标签:
原文地址:http://www.cnblogs.com/jinhaoObject/p/4544646.html