映射表与其他字段codefirst

时间:2016-07-11 15:16:38

标签: c# migration code-first

我首先使用代码,我有这个映射表

 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);

0 个答案:

没有答案