title: Error in calling savechanges
body: <p>I have the following code using Entity Framework:</p>
  
  <pre><code>try
  {
      using (GameDatabaseEntities context = new GameDatabaseEntities())
      {
          IQueryable&lt;Game&gt; games = context.Games.Where(a =&gt; a.isValidGame == false);
  
          foreach (Game item in games)
          {
              context.Games.Remove(item);
          }
  
          context.SaveChanges();
      }
  }
  catch (Exception ex)
  {
      ErrorHandler.ExceptionHandling("Error in `DeleteFalseFlagsDataAccess` method", ex);
  }
  </code></pre>
  
  <p>I sometimes get the following error:</p>
  
  <blockquote>
    <p>An error occurred while updating the entries.</p>
    
    <p>StackTrace<br>
    at System.Data.Entity.Internal.InternalContext.SaveChanges()<br>
    at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()<br>
    at System.Data.Entity.DbContext.SaveChanges()<br>
    at Game.DataAccessLayer.DeleteFalseFlagsDataAccess() in C:\Users\Media Depp\documents\visual studio 2017\Projects\Games\Game\Game
  </blockquote>
  
  <p>I do not know the reason, should I call <code>context.SaveChanges()</code> inside the <code>foreach</code>? thanks for helps. I should mention that I have read <a href="https://stackoverflow.com/questions/14269765/when-to-call-savechanges">here</a>, and according to the first answer there is no difference, and my code is not wrong. I get confused because I did not find the answer on web. I also have to refer to this point that I get the error in the line which I'm calling the <code>SaveChanges</code> instance method.<br />
  <hr />
  Edit: <br />
  I get the following inner message:<br /></p>
  
  <blockquote>
    <p>Message = "Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.\r\nThe statement has been terminated."</p>
  </blockquote>
  
  <p><br />
  Edit 2:<br />
  I have to mention that I am calling this from another thread. but as you see, I am creating the context inside the new thread and I don't think it matters.</p>