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.
.NET Entity Framework how to add navigation property
-
28-11-2021 - |
Pergunta
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?
Solução