Note that there are some explanatory texts on larger screens.

plurals
  1. POentity-framework error: An object with the same key already exists in the ObjectStateManager
    primarykey
    data
    text
    <p>I got thiserror</p> <blockquote> <p>An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.</p> </blockquote> <p>only because this line</p> <pre><code>oldProject = db.Projectes.Find(project.ID); </code></pre> <p><strong>I need it in order to get the object before the edit, and afterwards compare the values changes between before and after the edit</strong>, I do it in the third if statement (that compare one values), and in the "SFSiteEmailSend.ProjectEdited" function that only check the changes and send email about it.</p> <p>By the way, I never change the "oldproject", the error still exist even if I delete all the email funcation and the third(last) if statement.</p> <pre><code> // POST: /Project/Edit/5 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit(Project project) { if (ModelState.IsValid) { // For Email Send - start string UrlProject = Request.Url.GetLeftPart(UriPartial.Authority) + Url.Action("Detail", "Project", new { id = project.ID }); Project oldProject = new Project(); Project newProject = new Project(); newProject = project; oldProject = db.Projectes.Find(project.ID); SFSiteEmailSend.ProjectEdited(oldProject, newProject, UrlProject); // For Email Send - end if (oldProject.Finished == false &amp;&amp; newProject.Finished == true) { project.DateFinished = DateTime.Now; } db.Entry(project).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(project); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload