title: Transaction not working with Web API .net core 2.2
body: <p>I have a async web API that has services and a connection to the db using an EF context.
  In one of the services, where I inject the context using DI I want to make a simple transactional service, like:</p>
  
  <pre><code>public async Task&lt;int&gt; ServiceMethod()
  {
      using (var transaction = context.Database.BeginTransaction())
      {
           await context.Table1.AddAsync(new Table1());
           await context.SaveChangeAsync();
  
           CallOtherservice(context);
           await context.SaveChangeAsync();
  
           transaction.Commit();   
      }
  }
  
  CallOtherService(Context context)
  {
       await context.Table2.AddAsync();
  }
  </code></pre>
  
  <p>I have now mocked CallOtherService() to throw an exception and I expect nothing to be commited, but it looks like changes to Table1 persist, amid the transaction trhat should stop them. I have tried calling Rollback() in a try catch statement and using a TransactionScope() instead, but both were useless. Also, I have noticed that after calling .BeginTransaction(), context.Database.CurrentTransaction is null, which I consider a bit weird.</p>
  
  <p>EDIT:
  the method that I test:</p>
  
  <pre><code>public async Task&lt;int&gt; AddMatchAsync(Models.Database.Match match)
          {
              //If match is null, nothing can be done
              if (match == null)
                  return 0;
              else
              {
                  using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                  {
                      try
                      {
                          //If the match already exists, return its id
                          var dbId = await ExistsMatchAsync(match.HomeTeam.Name, match.AwayTeam.Name, match.Time);
                          if (dbId &gt; 0)
                          {
                              log.Info($"Found match with id {dbId}");
                              return dbId;
                          }
  
                          //add computable data
                          match = await AttachMatchName(match);
                          match.Season = CommonServices.toSeason(match);
  
                          // Prepare the relational entities accordingly
                          match = PrepareTeamsForAddMatch(match).Result;
                          match = PrepareLeagueForAddMatch(match).Result;
  
                          //add the match and save it to the DB
                          await context.Matches.AddAsync(match);
                          await context.SaveChangesAsync();
                          log.Info($"Successfully added a new match! id: {match.Id}");
  
                          // Create new TeamLeagues entities if needed
                          leaguesService.CreateTeamLeaguesForNewMatchAsync(context, match);
                          await context.SaveChangesAsync();
  
                          scope.Complete();
                          return match.Id;
                      }
                      catch (Exception ex)
                      {
                          log.Error($"Error adding match - Rolling back: {ex}");
                          throw;
                      }
  
                  }
              }
          }
  </code></pre>
  
  <p>and the test:</p>
  
  <pre><code>        [Test] 
          public void AddMatchSaveChangesTransaction()
          {
              //Arrange
              var exceptiontext = "This exception should prevent the match from being saved";
              var leagueServiceMock = new Mock&lt;ILeaguesService&gt;();
              leagueServiceMock.Setup(p =&gt; p.CreateTeamLeaguesForNewMatchAsync(It.IsAny&lt;InFormCoreContext&gt;(),It.IsAny&lt;Match&gt;()))
                  .Throws(new Exception(exceptiontext));
  
              leagueServiceMock.Setup(p =&gt; p.GetLeagueAsync(It.IsAny&lt;string&gt;()))
                  .ReturnsAsync((string name) =&gt; new League{Id = 1, Name = name });
  
              var match = new Match
              {
                  HomeTeam = new Team { Name = "Liverpool" },
                  AwayTeam = new Team { Name = "Everton" },
                  League = new League { Name = "PL", IsSummer = true },
                  Time = DateTime.UtcNow,
                  HomeGoals = 3,
                  AwayGoals = 0
              };
              var mcount = context.Matches.Count();
  
              //Act
              var matchService = new MatchesService(context, leagueServiceMock.Object, new LogNLog(), TeamsService);
  
              //Assert
              var ex = Assert.ThrowsAsync&lt;Exception&gt;(async () =&gt; await matchService.AddMatchAsync(match));
              Assert.AreEqual(ex.Message, exceptiontext); 
  
              Assert.AreEqual(mcount, context.Matches.Count(), "The match has been added - the transaction does not work");
          }`
  ```
  </code></pre>