title: Inserting Item in Database: Store update, insert, or delete statement affected an unexpected number of rows (0)
body: <p>I tried to write a simple create-method like I build a several times, but this time, i get this error over and over:</p>
  <pre><code>Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.
  </code></pre>
  <p>I also tried the recommendet procedure in the link given by the exception:</p>
  <pre><code>            catch (DbUpdateConcurrencyException dbex)
              {
                  dbex.Entries.Single().Reload();
              }
  </code></pre>
  <p>But then following error occured the next:</p>
  <pre><code>Refresh cannot be used for entities in the Added state
  </code></pre>
  <p>What is understandable, I calling the Add-Method and so there should be nothing to refresh, right?</p>
  <p>Most cases I found online are for the Update-method and so not what I'm looking for.</p>
  <p>I also tried this, but the exception is not triggered by the error.
  catch (DbUpdatableDataRecord ex)
  {
  return Json(ex.DataRecordInfo, JsonRequestBehavior.AllowGet);
  }</p>
  <p>Model:</p>
  <pre><code>public class ForecastItem
  {
      [Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int ID { get; set; }
  
      [Required( ErrorMessage = &quot;Bitte ein Datum auswählen.&quot; )]
      [Display( Name = &quot;Datum&quot; )]
      public DateTime Date { get; set; }
  
      [Required( ErrorMessage = &quot;Bitte ein Projekt auswählen.&quot; )]
      [Display( Name = &quot;Projekt-ID&quot; )]
      public int ProjectId { get; set; }
  
      [Required( ErrorMessage = &quot;Bitte einen Preis eingeben.&quot; )]
      [Display( Name = &quot;Preis&quot; )]
      public decimal Price { get; set; }
  
      [Required( ErrorMessage = &quot;Bitte einen Tickettyp hinterlegen.&quot; )]
      [Display( Name = &quot;Tickettyp&quot; )]
      public string TicketType { get; set; }
  
      [Required( ErrorMessage = &quot;Bitte einen Abrechnungstyp auswählen.&quot; )]
      [Display( Name = &quot;Abrechnungstyp&quot; )]
      public string AccountingType { get; set; }
  
      [Required(ErrorMessage = &quot;Bitte ein Ziel-Projektvolumen angeben.&quot;)]
      [Display(Name = &quot;Zielvolumen&quot;)]
      public int TargetVolume { get; set; }
  
      [Display(Name = &quot;Projekt&quot;)]
      public virtual Project Project { get; set; }
  }
  </code></pre>
  <p>Method:</p>
  <pre><code>public JsonResult addForecastItem(string newDate, int newProjectId, int newForecastVolume, string newTicketType, string newCalcType, decimal newPrice)
      {
          ForecastItem fi = new ForecastItem
          {
              AccountingType = newCalcType,
              Date = DateTime.Now,
              Price = newPrice,
              ProjectId = newProjectId,
              TargetVolume = newForecastVolume,
              TicketType = newTicketType
          };
  
          if ( ModelState.IsValid)
          {
              try
              {
                  db.ForecastItems.Add(fi);
                  db.SaveChanges();
              }
              catch (Exception e)
              {
                  return Json(e.Message, JsonRequestBehavior.AllowGet);
              }
          }
  
          return Json(fi, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  <p>Any idea I made wrong here?
  The Model is valid and the database inserts from other parts of the software.</p>