当我试图保存我的权利时,我有这个例外:
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
这是生成此异常的代码:
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);
这是方法AddBuzzMate:
public void AddBuzzMate(BuzzMate buzzMate)
{
_buzzMateRepository.Insert(buzzMate);
_buzzMateRepository.Save();
}
当我试图保存buzzmate时我有异常
答案 0 :(得分:1)
问题很可能是p
。不要使用会话中存储的实体进行持久性,否则您将无法避免此错误。尝试创建p
的克隆并将其分配给buzzmate
,如果您使用相同的EF上下文加载socialcampaign
并保留buzzmate
,则应该有效。