diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs index b73f79dd..10b2166f 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs @@ -216,17 +216,7 @@ public class OpenIddictEntityFrameworkApplicationStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TApplication application ? application : await QueryAsync(); - - TApplication? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from application in context.Set() - where application.Id!.Equals(key) - select application).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync(cancellationToken, [key]); } /// diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs index 87716235..98e4692e 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs @@ -230,17 +230,7 @@ public class OpenIddictEntityFrameworkAuthorizationStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TAuthorization authorization ? authorization : await QueryAsync(); - - TAuthorization? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from authorization in context.Set().Include(authorization => authorization.Application) - where authorization.Id!.Equals(key) - select authorization).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync(cancellationToken, [key]); } /// diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs index 376841b1..2e37889e 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkResourceStore.cs @@ -134,17 +134,7 @@ public class OpenIddictEntityFrameworkResourceStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TResource resource ? resource : await QueryAsync(); - - TResource? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from resource in context.Set() - where resource.Id!.Equals(key) - select resource).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync(cancellationToken, [key]); } /// diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs index 98c07069..cdfea2dd 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs @@ -134,17 +134,7 @@ public class OpenIddictEntityFrameworkScopeStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TScope scope ? scope : await QueryAsync(); - - TScope? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from scope in context.Set() - where scope.Id!.Equals(key) - select scope).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync(cancellationToken, [key]); } /// diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs index b8c83f39..80d3afcb 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs @@ -225,17 +225,7 @@ public class OpenIddictEntityFrameworkTokenStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TToken token ? token : await QueryAsync(); - - TToken? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from token in context.Set().Include(token => token.Application).Include(token => token.Authorization) - where token.Id!.Equals(key) - select token).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync(cancellationToken, [key]); } /// diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs index 5fc227bb..94882ef4 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs @@ -267,17 +267,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TApplication application ? application : await QueryAsync(); - - TApplication? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from application in context.Set().AsTracking() - where application.Id!.Equals(key) - select application).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync([key], cancellationToken); } /// diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs index a32af735..23fa9e1e 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs @@ -278,17 +278,7 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TAuthorization authorization ? authorization : await QueryAsync(); - - TAuthorization? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from authorization in context.Set().Include(authorization => authorization.Application).AsTracking() - where authorization.Id!.Equals(key) - select authorization).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync([key], cancellationToken); } /// diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs index ad668fb5..701e8683 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreResourceStore.cs @@ -137,17 +137,7 @@ public class OpenIddictEntityFrameworkCoreResourceStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TResource resource ? resource : await QueryAsync(); - - TResource? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from resource in context.Set().AsTracking() - where resource.Id!.Equals(key) - select resource).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync([key], cancellationToken); } /// diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs index cda95a0e..fcb698f0 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs @@ -137,17 +137,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TScope scope ? scope : await QueryAsync(); - - TScope? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from scope in context.Set().AsTracking() - where scope.Id!.Equals(key) - select scope).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync([key], cancellationToken); } /// diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs index 9790ed37..24d64199 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs @@ -239,17 +239,7 @@ public class OpenIddictEntityFrameworkCoreTokenStore< var context = await Context.GetDbContextAsync(cancellationToken); var key = ConvertIdentifierFromString(identifier); - return GetTrackedEntity() is TToken token ? token : await QueryAsync(); - - TToken? GetTrackedEntity() => - (from entry in context.ChangeTracker.Entries() - where entry.Entity.Id is TKey identifier && identifier.Equals(key) - select entry.Entity).FirstOrDefault(); - - Task QueryAsync() => - (from token in context.Set().Include(token => token.Application).Include(token => token.Authorization).AsTracking() - where token.Id!.Equals(key) - select token).FirstOrDefaultAsync(cancellationToken); + return await context.Set().FindAsync([key], cancellationToken); } ///