public class Employee
{
public virtual Department Department { get;set;}
}
public class Department
{
public virtual ICollection Employees { get; set; }
}
// Insert
var department = dbContext.Departments.FirstOrDefault(x => ...);
if (department != null)
{
department.Employees.Add(new Employee() { });
}
dbContext.SaveChanges();
你试试行不行?
还有,贴代码的时候最好贴完整点,不然不好分析问题。