title: How to totally lock a row in Entity Framework
body: <p>I am working with a situation where we are dealing with money transactions.</p>
  
  <p>For example, I have a table of users wallets, with their balance in that row.</p>
  
  <pre><code>UserId; Wallet Id; Balance
  </code></pre>
  
  <p>Now in our website and web services, every time a certain transaction happens, we need to:</p>
  
  <ol>
  <li>check that there is enough funds available to perform that transaction:</li>
  <li>deduct the costs of the transaction from the balance. </li>
  </ol>
  
  <p>How and what is the correct way to go about locking that row / entity for the entire duration of my transaction?</p>
  
  <p>From what I have read there are some solutions where EF marks an entity and then compares that mark when it saves it back to the DB, however what does it do when another user / program has already edited the amount?</p>
  
  <p>Can I achieve this with EF? If not what other options do I have?</p>
  
  <p>Would calling a stored procedure possibly allow for me to lock the row properly so that no one else can access that row in the SQL Server whilst program A has the lock on it?</p>