我有以下情况
public class Parent
{
public virtual long Id {get;set;}
public virtual Other other {get;set;}
}
public class Other {
public virtual long Id {get;set;}
public virtual string Description{get;set;}
}
......
var other = context.Others.getById(1);
var parent = new Parent(){Other = other};
context.Parent.Add(parent);
context.SaveChanges();
当我尝试保存父对象时,实体框架尝试再次保存其他对象并抛出此异常: 违反PRIMARY KEY约束。无法在对象中插入重复键-SQL Server