title: how to resolve the error "An item with the same key has already been added"
body: <p>Hello I am doing a job for the school and I used asp.net mvc to create the page and make the connection to the database. But when I insert an error "An item with the same key has already been added". I checked my tables and my procedures and the variable "ID" increases.
  And if inserting in the database there is no error. Anyone who can help me?
  Thank you to anyone who wasted their time helping me.Thanks.</p>
  
  <blockquote>
    <p>Class TransController, 
    method executed after the Create button on the web page is pressed</p>
  </blockquote>
  
  <pre><code> [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = "ID,Titulo,Data,Imagem,Descricao,Tipo")] Transmontanos TM)
      {
  
          if (ModelState.IsValid)
          {
              if (Request.Files != null &amp;&amp; Request.Files[0] != null)
              {
                  var fileName = Request.Files[0].FileName;
                  var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
                  Request.Files[0].SaveAs(path);
  
                  var ms = new MemoryStream();
                  var img = Image.FromFile(path);
                  img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  
                  TM.Imagem = ms.ToArray();
              }
  
              Services.AddObject(TM);
  
              return RedirectToAction("Index");
          }
  
          return View(TM);
      }
  </code></pre>
  
  <blockquote>
    <p>Class Services</p>
  </blockquote>
  
  <pre><code> public static void AddObject(Transmontanos TM)
      {
          using (var db = new TransmontanosEntities())
          {
             var result= db.GetType(TM.Tipo).FirstOrDefault();
  
              db.Add_object(TM.Titulo, TM.Data, TM.Imagem, TM.Descricao, result.ID);
  
          }
      }
  </code></pre>
  
  <blockquote>
    <p>Database (Table
    <a href="https://i.stack.imgur.com/HpwhM.png" rel="nofollow noreferrer">image</a> ; Stored Procedure Add_object
    <a href="https://i.stack.imgur.com/mzxwQ.png" rel="nofollow noreferrer">image</a> )</p>
    
    <p>Structure of my project
    <a href="https://i.stack.imgur.com/uLtvq.png" rel="nofollow noreferrer">image</a> </p>
    
    <p>Error
    <a href="https://i.stack.imgur.com/NYbmU.png" rel="nofollow noreferrer">image</a></p>
  </blockquote>