Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top