title: Custom constraint in EF fails, async issue
body: <p>I have a controller action like this (ASP.NET web api)</p>
  
  <pre><code>public HttpResponseMessage&lt;Component&gt; Post(Component c)
  {
      //Don't allow equal setup ids in within the same installation when the component is of type 5
      if (db.Components.Any(d =&gt; d.InstallationId == c.InstallationId &amp;&amp; d.SetupId == c.SetupId &amp;&amp; d.ComponentTypeId == 5)) return new HttpResponseMessage&lt;Component&gt;(c, HttpStatusCode.Conflict);
  
      db.Components.Add(c);
      db.SaveChanges();
      return new HttpResponseMessage&lt;Component&gt;(c, HttpStatusCode.OK);
  }      
  </code></pre>
  
  <p>I send a number of posts request from javascript with 2 of them being equal</p>
  
  <pre><code>{SetupId : 7, InstallationId : 1, ComponentTypeId: 5}
  </code></pre>
  
  <p>I have verified this both using fiddler and stepping through the code on the server.</p>
  
  <p>However sometimes the constraint that I do above is working as it should and other times it is not. I guess since Post is an async action the request #2 sometimes checks the database for duplicates BEFORE the first request have managed to save to the database.</p>
  
  <p>How can I solve this? Is there a way to lock EF operations to the database from beginning of the post action until the end? Is that even a good idea?</p>
  
  <p>I have though of database restraints, however, since this is only when componenttype is 5 then I'm not sure how to implement that. Or if it's even possible.</p>