title: System.Data.Entity.Infrastructure.DbUpdateConcurrencyException. Store update, insert, or delete statement affected an unexpected number of rows (0)
body: <p><strong>Models</strong>
  These are model classes and I am using Entity Framework. I am using these models to implement cascaded drop down list.</p>
  
  <pre><code>  public class League
      {
          public int Id { get; set; }
          public string League1 { get; set; }
          public string Icon { get; set; }
  
          public virtual ICollection&lt;LeagueDivision&gt; LeagueDivisions { get; set; }
      }
  
    public class LeagueDivision
      {
          public int Id { get; set; }
          public Nullable&lt;int&gt; LeagueId { get; set; }
          public string Name { get; set; }
          public string Icon { get; set; }
  
          public virtual League League { get; set; }
      }  
  
    public partial class CalculatorPrice
      {
          public int Id { get; set; }
          public int LeagueId { get; set; }
          public int LeagueDivisionId { get; set; }
          public Nullable&lt;decimal&gt; Price { get; set; }
      } 
  
   public class ViewModelForHostBooster
      {
          [Required(ErrorMessage = "Please enter price")]
          [Display(Name = "Price")]
          public decimal Price { get; set; }       
  
          [Required(ErrorMessage = "Please select a league")]
          [Display(Name = "League")]
  
          public int? SelectedLeague { get; set; }
          [Required(ErrorMessage = "Please select a league division")]
          [Display(Name = "League Division")]
  
          public int? SelectedLeagueDivision { get; set; }
  
          public SelectList LeagueList { get; set; }
          public SelectList LeagueDivisionList { get; set; }    
  
      }
  </code></pre>
  
  <p><strong>Controller/Actions</strong>
  In HttpGet I just populated cascaded dropdown list and working fine now I am implementing Httppost for this. I want to store <strong>price</strong>  depending upon selected list items from dropdown list and if the <strong>price</strong>  already exists then I want to update it. First time I can add <strong>price</strong> successfully but second time when I am trying to update it I am getting <strong>System.Data.Entity.Infrastructure.DbUpdateConcurrencyException</strong> Please can anybody guide me how to handle this.</p>
  
  <pre><code>[HttpPost]
   public ActionResult IndexDropDown(ViewModelForHostBooster model)
      {
          if (!ModelState.IsValid)
          {
              ConfigureViewModel(model);
              return View(model);
          }
          else
          {
              HostBoostersDBEntities2 db = new HostBoostersDBEntities2();
              CalculatorPrice calculatePrice = new CalculatorPrice();
               var  calculatePriceExistsOrNot =  db.CalculatorPrices
                  .Where(x =&gt; x.LeagueId == model.SelectedLeague
                      &amp;&amp;
                      x.LeagueDivisionId == model.SelectedLeagueDivision).ToList();
               if (calculatePriceExistsOrNot.Count &gt; 0)
              {
  
                  calculatePrice.LeagueId = (int)model.SelectedLeague;
                  calculatePrice.LeagueDivisionId = (int)model.SelectedLeagueDivision;
                  calculatePrice.Price = model.Price;
                  db.Entry(calculatePrice).State = EntityState.Modified;
  </code></pre>
  
  <blockquote>
    <p><strong>Exception occurs here in line db.SaveChanges();</strong>
    'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in EntityFramework.dll but was not handled in user code.
    Additional information: 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.</p>
  </blockquote>
  
  <pre><code>                db.SaveChanges();
              }
              else
              {
                  calculatePrice.LeagueId = (int)model.SelectedLeague;
                  calculatePrice.LeagueDivisionId = (int)model.SelectedLeagueDivision;
                  calculatePrice.Price = model.Price;
                  db.CalculatorPrices.Add(calculatePrice);
                  db.SaveChanges();
              }
  
  
          }
          ConfigureViewModel(model);
          return View(model);
      }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>  @using (Html.BeginForm("IndexDropDown", "DropDown", FormMethod.Post,
                                        new { enctype = "multipart/form-data" }))
  {
      &lt;div&gt;
          @Html.LabelFor(m =&gt; m.Price, new { @class ="control-lebel"})
          @Html.TextBoxFor(m =&gt; m.Price, new { @class = "form-control"})
          @Html.ValidationMessageFor(m =&gt; m.Price)
      &lt;/div&gt;
  
      &lt;div&gt;
          @Html.LabelFor(m =&gt; m.SelectedLeague ,new { @class ="control-lebel"})
          @Html.DropDownListFor(m =&gt; m.SelectedLeague, Model.LeagueList, new { @class = "form-control"})
          @Html.ValidationMessageFor(m =&gt; m.SelectedLeague)
      &lt;/div&gt;
      &lt;div&gt;
          @Html.LabelFor(m =&gt; m.SelectedLeagueDivision ,new { @class ="control-lebel"})
          @Html.DropDownListFor(m =&gt; m.SelectedLeagueDivision, Model.LeagueDivisionList, new { @class = "form-control" })
          @Html.ValidationMessageFor(m =&gt; m.SelectedLeagueDivision)
      &lt;/div&gt;
      &lt;input type="submit" value="save" /&gt;
  }
  </code></pre>