i when i try to save my entitie buzzmate i have this exception :
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
this is the code that generate this exception :
var p = Session["mayaProfile"] as MayaProfile;
BuzzMate buzzmate = new BuzzMate();
buzzmate.MayaProfile = p;
SocialBuzzCompaign socialcampaign = _buzzService.GetSocialBuzzCompaign(model.socialBuzzCompaignId);
//Ajouter le BuzzMate
buzzmate.SocialBuzzCompaign = socialcampaign;
buzzmate.JoiningStatus = JoiningStatus.Approved;
buzzmate.SelectionType = BuzzMateSelectionType.InvitedByBuzzLeader;
//try
//
_buzzService.AddBuzzMate(buzzmate);
and this is method AddBuzzMate :
public void AddBuzzMate(BuzzMate buzzMate)
{
_buzzMateRepository.Insert(buzzMate);
_buzzMateRepository.Save();
}
when i try to save buzzmate i have exception
The problem is most probably
p. Don’t use entities stored in session for persistence or you will not avoid this error. Try to create clone ofpand assign it tobuzzmateand if you use same EF context for loadingsocialcampaignand persistingbuzzmateit should work.