diff --git a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs
index cd9695f9..f52903eb 100644
--- a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs
+++ b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkHelpers.cs
@@ -9,6 +9,7 @@ using System.Runtime.CompilerServices;
using Microsoft.Extensions.DependencyInjection;
using OpenIddict.EntityFramework;
using OpenIddict.EntityFramework.Models;
+using OpenIddict.Extensions;
namespace System.Data.Entity;
@@ -86,4 +87,28 @@ public static class OpenIddictEntityFrameworkHelpers
}
}
}
+
+ ///
+ /// Tries to create a new with the specified .
+ ///
+ /// The Entity Framework context.
+ /// The desired level of isolation.
+ /// The if it could be created, otherwise.
+ internal static DbContextTransaction? CreateTransaction(this DbContext context, IsolationLevel level)
+ {
+ if (context is null)
+ {
+ throw new ArgumentNullException(nameof(context));
+ }
+
+ try
+ {
+ return context.Database.BeginTransaction(level);
+ }
+
+ catch (Exception exception) when (!OpenIddictHelpers.IsFatal(exception))
+ {
+ return null;
+ }
+ }
}
diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs
index 941d2b7d..392ef6e5 100644
--- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs
+++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs
@@ -18,7 +18,6 @@ using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.EntityFramework.Models;
-using OpenIddict.Extensions;
using static OpenIddict.Abstractions.OpenIddictExceptions;
namespace OpenIddict.EntityFramework;
@@ -133,19 +132,6 @@ public class OpenIddictEntityFrameworkApplicationStore> ListAuthorizationsAsync()
=> (from authorization in Authorizations.Include(authorization => authorization.Tokens)
where authorization.Application!.Id!.Equals(application.Id)
@@ -160,7 +146,7 @@ public class OpenIddictEntityFrameworkApplicationStore> ListTokensAsync()
=> (from token in Tokens
where token.Authorization!.Id!.Equals(authorization.Id)
@@ -151,7 +138,7 @@ public class OpenIddictEntityFrameworkAuthorizationStore