故事:
当我尝试保存某些内容时出现一个奇怪的错误,我收到了此错误消息
一个实体对象不能被多个 IEntityChangeTracker 实例引用。
我真的不知道那是什么,为什么会出现,只有当我尝试保存我的插入和更新正在工作的东西时才会出现,只有当我尝试从 Telerik 网格中将某些东西保存在 db 中时才会出现
if (this.annualVacationList != null)
{
List<AnnualVacation> vacationToSave = this.annualVacationList;
IEnumerable<AnnualVacation> existing = paramUser.AnnualVacations;
foreach (AnnualVacation toSave in vacationToSave)
{
AnnualVacation existingItem = existing.Where(x => x.AnnualVacationId == toSave.AnnualVacationId).SingleOrDefault();
if (existingItem == null)
{
ctx.AddToAnnualVacations(toSave);
}
else
{
existingItem.FromDate = toSave.FromDate;
existingItem.ToDate = toSave.ToDate;
existingItem.WorkingTime = toSave.WorkingTime;
existingItem.VacationDays = toSave.VacationDays;
}
}
}
ctx.SaveChanges();
}
调试后,我看到代码在 Project.Name.Designer.cs 中停止运行 ..... Oo
public void AddToAnnualVacations(AnnualVacation annualVacation)
{
base.AddObject("AnnualVacations", annualVacation);
}