title: Flood requests to an action causes unpredictable behavior - ASP.NET MVC
body: <p>Asp.Net MVC 5 - I have a table in database which has three column: Id (primary key), CreateDateTime and DeleteDateTime.
  DeleteDateTime of last inserted item is null and table has one item with empty DeleteDateTime at any time.</p>
  
  <p>here is my code in action (inside controller):</p>
  
  <pre><code>//find active row in database
  var activeRow = db.TableName.SingleOrDefault(t =&gt; !t.DeleteDateTime.HasValue);
  
  //if there is no any active row
  if (activeRow == null)
  {
      db.TableName.Add(new TableName()
      {
          DeleteDateTime = null,
          CreateDateTime = DateTime.Now
      });
  }
  else
  {
      //deactive selected row
      activeRow.DeleteDateTime = DateTime.Now;
  
      //add new row which is active (DeleteDateTime is null)
      db.TableName.Add(new TableName()
      {
          DeleteDateTime = null,
          CreateDateTime = DateTime.Now
      });
  }
  db.SaveChanges();
  </code></pre>
  
  <p>The problem arises when action get multiple requests at a time. in this code table should not have more than one item with empty DeleteDateTime but I test my action with many request at the same time and I see this result:
  <a href="https://i.stack.imgur.com/ifOvn.png" rel="nofollow noreferrer">result in database (tow null item with same CreateDateTime)</a> </p>