문제

I have created data base model with entity framework which have relation many to many between recipients and mailing lists. When i generated data base it didn't give me acces to link table but just to property in recipient - recipient.mailingList. I tried to add new recipient to data base and created new one, added all properties correctly. checked and it worked. but when i added MailingList to Recipient it gave me error: "English translation: An entity object cannot be referenced by multiple instances of IEntityChangeTracker.". I added MailingList as follows.

Recipient newRecipient = new Recipient();

// some added properties.

newRecipient.MailingList.Add(chosenMailingList);
context.Rcipients.AddObject(newRecipient);

Before error I can see that newRecipient has mailingLists added. Program added newRecipient without problem before i tried to assign MailingList.Can Anyone tell me how to add mailing lists to recipients?

도움이 되었습니까?

해결책

I think your accidentally have two contexts alive at the same time. You must get chosenMailingList from the same context instance where you add the new recipient.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top