我有两张名为
的三张桌子
语言,语言类型,员工
语言类型字段为 LId,LanguageType
语言领域 LId,EmpId,语言流畅
员工的字段是 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);
}
}
答案 0 :(得分: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();
}
}