title: Store update, insert, or delete statement affected an unexpected number of rows (0) after context.refresh()
body: <p>I am trying to <code>insert</code> by using EF and pasing all parameters but still for some reason I am getting <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. Refresh ObjectStateManager entries.</code> error.</p>
  
  <p>I looked into <a href="https://stackoverflow.com/questions/6819813/solution-for-store-update-insert-or-delete-statement-affected-an-unexpected-n">Solution for: Store update, insert, or delete statement affected an unexpected number of rows (0)</a> and <a href="https://stackoverflow.com/questions/13177718/dbcontext-does-not-contain-a-definition-for-refresh">dbcontext does not contain a definition for &#39;Refresh&#39;</a> but still I am getting the error.</p>
  
  <p>I tried following approaches:</p>
  
  <pre><code>foreach (var mainItemDeliveryTag in mainItemDeliveryTagList)
  {
      try
      {   //Option-1
          var mainItemTag = DataContext.Set&lt;MainItemDeliveryTag&gt;();
          mainItemTag.Add(new MainItemDeliveryTag { MainItemID = mainItemId, DeliveryProviderTagID = mainItemDeliveryTag.DeliveryProviderTagID, IsDeliveryTagSelected = mainItemDeliveryTag.IsDeliveryTagSelected });
  
          //Option-2
          var mainItemDeliveryTagObj = new MainItemDeliveryTag()
          {
              MainItemID = mainItemId,
              DeliveryProviderTagID = mainItemDeliveryTag.DeliveryProviderTagID,
              IsDeliveryTagSelected = mainItemDeliveryTag.IsDeliveryTagSelected,
          };
          DataContext.MainItemDeliveryTag.Add(mainItemDeliveryTagObj);
  
          //Option-3
          DataContext.Entry(mainItemDeliveryTag).State = System.Data.Entity.EntityState.Added;
  
          DataContext.SaveChanges();
      }
      catch (OptimisticConcurrencyException)
      {
          var ctx = ((IObjectContextAdapter)DataContext).ObjectContext;
          ctx.Refresh(RefreshMode.ClientWins, mainItemDeliveryTag);
          DataContext.SaveChanges();
      }
  }
  </code></pre>
  
  <p>What am I missing here?</p>