我已经使用实体框架创建了数据库模型,该模型在收件人和邮件列表之间具有多对多的关系。当我生成数据库时,它没有让我访问链接表,而只是访问收件人中的属性-recipient.mailingList。我尝试将新收件人添加到数据库并创建新收件人,正确添加了所有属性。检查并有效。但是当我将 MailingList 添加到收件人时,它给了我错误:“英文翻译:IEntityChangeTracker 的多个实例无法引用实体对象。”。我添加了 MailingList 如下。
Recipient newRecipient = new Recipient();
// some added properties.
newRecipient.MailingList.Add(chosenMailingList);
context.Rcipients.AddObject(newRecipient);
在出错之前,我可以看到 newRecipient 添加了 mailingLists。在我尝试分配 MailingList 之前,程序添加了 newRecipient 没有问题。谁能告诉我如何将邮件列表添加到收件人?