Entity framework 4 更新子&x27;s记录,在主表中插入新记录

Entity framework 4 更新子&x27;s记录,在主表中插入新记录,entity-framework-4,parent-child,Entity Framework 4,Parent Child,我有两个实体,即 public class Employee { public int ID{get;set;} public string value{get;set;} public int DepartmentID{get;set;} public virtual Department department {get;set;} } public class Department { public int ID{get;set;} public string

我有两个实体,即

public class Employee
{
  public int ID{get;set;}
  public string value{get;set;}
  public int DepartmentID{get;set;}
  public  virtual Department department {get;set;}
}

public class Department
{
   public int ID{get;set;}
   public string Name{get;set;}
} 
我正在使用存储库模式和DTO。我正在使用EF4访问SQL server 2008中的数据。我能够从employee表中检索数据以及引用的数据。问题是当我在业务逻辑中更新子表中的记录时,将在主表中插入一条新记录,然后在子表中引用该记录的ID


有人能帮我吗?

所以新记录有了新ID?是的。新记录有了新ID告诉我们如何更新记录我正在使用值注入器将数据映射到实体。然后我正在使用dbContext.Set()插入。添加(对象);