[英]EntityFramework code first Exception
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 : 这是方法AddBuzzMate:
public void AddBuzzMate(BuzzMate buzzMate)
{
_buzzMateRepository.Insert(buzzMate);
_buzzMateRepository.Save();
}
when i try to save buzzmate i have exception 当我尝试保存Buzzmate时出现异常
The problem is most probably p
. 问题很可能是p
。 Don't use entities stored in session for persistence or you will not avoid this error. 请勿将存储在会话中的实体用于持久性,否则您将避免此错误。 Try to create clone of p
and assign it to buzzmate
and if you use same EF context for loading socialcampaign
and persisting buzzmate
it should work. 尝试创建p
克隆并将其分配给buzzmate
,如果您使用相同的EF上下文来加载socialcampaign
和持久保留buzzmate
则它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.