0

我有两个三个表,分别命名为
Language、Language Type、Employee

语言类型字段为LId,LanguageType

语言领域是LId,EmpId,Language Fluency

Employee 的字段是EmpId ,EmpName

语言类型和语言之间的关系是一对一的,语言和员工表是多对一的。问题是当我用语言输入数据时,它会显示错误

A dependent property in a Referential Constraint is mapped 
to a store-generated column. Column: 'LId'."}.

即使数据被插入到语言类型而不是语言表中。lINQ 查询是针对语言表的

public void AddEmpLanguage(Language language, long id)   
{ 
   using (var context = new HRMSEntities())
  {
       Language emp = new Language
       {
            EmpId = id,
            LanguageFluency = language.LanguageFluency,
        };
       context.Language.AddObject(emp);
   }
}
4

1 回答 1

0

您可以尝试将语言直接添加到员工对象

public void AddEmpLanguage(Language language, long empId)   
{ 
    using (var context = new HRMSEntities())
    {
        Language lang = new Language
        {
            LanguageFluency = language.LanguageFluency,
        };
        var employee = context.Employees.Find(empId);
        /*          or context.Employees.FirstOrDefault(x=>x.ID == empId); */
        if(employee != null){
            employee.Languages.Add(lang);
        }
        context.SaveChanges();
    }
}
于 2012-08-08T12:07:16.837 回答