Here is my code:
public ActionResult DeleteItem(int id)
{
using (var cont = new PhotoGalleryDBEntities4())
{
var refToDel = cont.Referanslars.First(x => x.Id == id);
if (!ModelState.IsValid)
return Content("Referans bulunamadı!");
_db.Attach(refToDel);
_db.DeleteObject(refToDel);
_db.SaveChanges();
return View();
}
return View();
}
I am getting error in _db.Attach() that is:An entity object cannot be referenced by multiple instances of IEntityChangeTracker. Why is this happenning?
Here is a link for how someone else got rid of their “An entity object cannot be referenced by multiple instances of IEntityChangeTracker.” problem. I hope this helps.
stackoverflow link