我首先使用代码,我有这个映射表
public class OpirtiunitiesSourcerUsers
{
[Key, Column(Order = 0)]
[ForeignKey("SourcedUser")]
public int SourcedUserID { get; set; }
[Key, Column(Order = 1)]
[ForeignKey("SourcedPartner")]
public int SourcedPartnerID { get; set; }
public virtual SourcedUser SourcedUser { get; set; }
public virtual SourcedPartner SourcedPartner { get; set; }
public string ApproversRole { get; set; }
}
当我尝试添加新的OpirtiunitiesSourcerUsers时抛出异常 IEntityChangeTracker的多个实例无法引用实体对象。
OpirtiunitiesSourcerUsers opp1 = new OpirtiunitiesSourcerUsers()
{
SourcedUser = someUser,
ApproversRole = "someRole",
SourcedPartner = somePartner
};
context.OpirtiunitiesSourcerUsers.Add(opp1);