From 318275e7a976d6cb3de4956b9bbc1104b1d3936d Mon Sep 17 00:00:00 2001 From: Markus Eggimann Date: Tue, 8 Dec 2020 08:52:09 +0100 Subject: [PATCH] Fix issues with event counters Fixes #23630 --- src/EFCore/ChangeTracking/Internal/StateManager.cs | 2 ++ src/EFCore/DbContext.cs | 6 ++++-- src/EFCore/Storage/ExecutionStrategy.cs | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/EFCore/ChangeTracking/Internal/StateManager.cs b/src/EFCore/ChangeTracking/Internal/StateManager.cs index faffa5c53cc..13a5431e9f0 100644 --- a/src/EFCore/ChangeTracking/Internal/StateManager.cs +++ b/src/EFCore/ChangeTracking/Internal/StateManager.cs @@ -1114,6 +1114,8 @@ protected virtual async Task SaveChangesAsync( { using (_concurrencyDetector.EnterCriticalSection()) { + EntityFrameworkEventSource.Log.SavingChanges(); + return await _database.SaveChangesAsync(entriesToSave, cancellationToken) .ConfigureAwait(false); } diff --git a/src/EFCore/DbContext.cs b/src/EFCore/DbContext.cs index 31efe9f5c3e..8f0d0ad35d5 100644 --- a/src/EFCore/DbContext.cs +++ b/src/EFCore/DbContext.cs @@ -112,6 +112,8 @@ public DbContext([NotNull] DbContextOptions options) ServiceProviderCache.Instance.GetOrAdd(options, providerRequired: false) .GetRequiredService() .InitializeSets(this); + + EntityFrameworkEventSource.Log.DbContextInitializing(); } /// @@ -347,8 +349,6 @@ private IServiceProvider InternalServiceProvider { _initializing = true; - EntityFrameworkEventSource.Log.DbContextInitializing(); - var optionsBuilder = new DbContextOptionsBuilder(_options); OnConfiguring(optionsBuilder); @@ -642,6 +642,8 @@ public virtual async Task SaveChangesAsync( } catch (DbUpdateConcurrencyException exception) { + EntityFrameworkEventSource.Log.OptimisticConcurrencyFailure(); + await DbContextDependencies.UpdateLogger.OptimisticConcurrencyExceptionAsync(this, exception, cancellationToken) .ConfigureAwait(false); diff --git a/src/EFCore/Storage/ExecutionStrategy.cs b/src/EFCore/Storage/ExecutionStrategy.cs index 16240197fa0..4f947f62023 100644 --- a/src/EFCore/Storage/ExecutionStrategy.cs +++ b/src/EFCore/Storage/ExecutionStrategy.cs @@ -273,6 +273,9 @@ private async Task ExecuteImplementationAsync( catch (Exception ex) { Suspended = false; + + EntityFrameworkEventSource.Log.ExecutionStrategyOperationFailure(); + if (verifySucceeded != null && CallOnWrappedException(ex, ShouldVerifySuccessOn)) {