title: What's the point of multiple SaveChanges inside an entity-framework-core transaction?
body: <p>I'm using EF for my .net-core application and I'm wondering what is the difference between calling <code>SaveChanges</code> multiple times during a transaction and only calling it once before committing. To better illustrate my question, I will provide some pseudo code.</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; AddDepositToHousehold(int householdId, DepositRequestModel model)
  {
      using (var transaction = await Context.Database.BeginTransactionAsync(IsolationLevel.Snapshot))
      {
          try
          {
              // Add the deposit to the database
              var deposit = this.Mapper.Map&lt;Deposit&gt;(model);
              await this.Context.Deposits.AddAsync(deposit);
  
              await this.Context.SaveChangesAsync();
  
              // Pay some debts with the deposit
              var debtsToPay = await this.Context.Debts
                  .Where(d =&gt; d.HouseholdId == householdId &amp;&amp; !d.IsPaid)
                  .OrderBy(d =&gt; d.DateMade)
                  .ToListAsync();
  
              debtsToPay.ForEach(d =&gt; d.IsPaid = true);
  
              await this.Context.SaveChangesAsync();
  
              // Increase the balance of the household
              var household = this.Context.Households
                  .FirstOrDefaultAsync(h =&gt; h.Id == householdId);
  
              household.Balance += model.DepositAmount;
  
              await this.Context.SaveChangesAsync();
  
              transaction.Commit();
              return this.Ok();
          }
          catch
          {
              transaction.Rollback();
              return this.BadRequest();
          }
      }
  } 
  </code></pre>
  
  <p>As you can see, there are 3 database operations that need to be executed in the transaction. Saving the deposit, updating the debts, and updating the household's balance. Now, I can choose to put <code>SaveChanges</code> after each operation, just like it is shown in the code above, or I can completely discard the first 2 calls to <code>SaveChanges</code> and the behavior of the method will not change in any way. Most of the examples I found on the web contain multiple calls to SaveChanges and I guess there must be some difference between the two approaches. Yet, I cannot find any information what this difference exactly is. Can somebody, please, shed some light on the issue?</p>