title: How can I lock a table on read, using Entity Framework?
body: <p>I have a SQL Server (2012) which I access using Entity Framework (4.1).
  In the database I have a table called URL into which an independent process feeds new URLs.
  An entry in the URL table can be in state "New", "In Process" or "Processed".</p>
  
  <p>I need to access the URL table from different <strong>computers</strong>, check for URL entries with status "New", take the first one and mark it as "In Process".</p>
  
  <pre><code>var newUrl = dbEntity.URLs.FirstOrDefault(url =&gt; url.StatusID == (int) URLStatus.New);
  if(newUrl != null)
  {
      newUrl.StatusID = (int) URLStatus.InProcess;
      dbEntity.SaveChanges();
  }
  //Process the URL
  </code></pre>
  
  <p>Since the query and update are not atomic, I can have two different computers read and update the same URL entry in the database.</p>
  
  <p>Is there a way to make the select-then-update sequence atomic to avoid such clashes?</p>