From 874dd44170835cccd7ae042720c8efd776d48b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sat, 5 Oct 2019 20:19:33 +0200 Subject: [PATCH] Add workarounds for API breaking changes introduced in Entity Framework Core 3.x --- .../OpenIddictApplicationConfiguration.cs | 5 ++++- .../OpenIddictScopeConfiguration.cs | 5 ++++- .../OpenIddictTokenConfiguration.cs | 5 ++++- .../Stores/OpenIddictAuthorizationStore.cs | 8 +++++++- .../Stores/OpenIddictTokenStore.cs | 16 ++++++++++++++-- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictApplicationConfiguration.cs b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictApplicationConfiguration.cs index 57c4c05c..c3db132a 100644 --- a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictApplicationConfiguration.cs +++ b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictApplicationConfiguration.cs @@ -40,7 +40,10 @@ namespace OpenIddict.EntityFrameworkCore builder.HasKey(application => application.Id); - builder.HasIndex(application => application.ClientId) + // Warning: the non-generic overlord is deliberately used to work around + // a breaking change introduced in Entity Framework Core 3.x (where a + // generic entity type builder is now returned by the HasIndex() method). + builder.HasIndex(nameof(OpenIddictApplication.ClientId)) .IsUnique(); builder.Property(application => application.ClientId) diff --git a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictScopeConfiguration.cs b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictScopeConfiguration.cs index b9389668..4a241b43 100644 --- a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictScopeConfiguration.cs +++ b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictScopeConfiguration.cs @@ -36,7 +36,10 @@ namespace OpenIddict.EntityFrameworkCore builder.HasKey(scope => scope.Id); - builder.HasIndex(scope => scope.Name) + // Warning: the non-generic overlord is deliberately used to work around + // a breaking change introduced in Entity Framework Core 3.x (where a + // generic entity type builder is now returned by the HasIndex() method). + builder.HasIndex(nameof(OpenIddictScope.Name)) .IsUnique(); builder.Property(scope => scope.ConcurrencyToken) diff --git a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictTokenConfiguration.cs b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictTokenConfiguration.cs index 7e3ff800..6cba70aa 100644 --- a/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictTokenConfiguration.cs +++ b/src/OpenIddict.EntityFrameworkCore/Configurations/OpenIddictTokenConfiguration.cs @@ -40,7 +40,10 @@ namespace OpenIddict.EntityFrameworkCore builder.HasKey(token => token.Id); - builder.HasIndex(token => token.ReferenceId) + // Warning: the non-generic overlord is deliberately used to work around + // a breaking change introduced in Entity Framework Core 3.x (where a + // generic entity type builder is now returned by the HasIndex() method). + builder.HasIndex(nameof(OpenIddictToken.ReferenceId)) .IsUnique(); builder.HasIndex( diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs index 2262df29..662c42b8 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs @@ -848,7 +848,13 @@ namespace OpenIddict.EntityFrameworkCore if (!string.IsNullOrEmpty(identifier)) { - var application = await Applications.FindAsync(new object[] { ConvertIdentifierFromString(identifier) }, cancellationToken); + var key = ConvertIdentifierFromString(identifier); + + // Warning: FindAsync() is deliberately not used to work around a breaking change introduced + // in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned). + var application = await Applications.AsQueryable() + .FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken); + if (application == null) { throw new InvalidOperationException("The application associated with the authorization cannot be found."); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs index 1611565b..2d65a32d 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs @@ -909,7 +909,13 @@ namespace OpenIddict.EntityFrameworkCore if (!string.IsNullOrEmpty(identifier)) { - var application = await Applications.FindAsync(new object[] { ConvertIdentifierFromString(identifier) }, cancellationToken); + var key = ConvertIdentifierFromString(identifier); + + // Warning: FindAsync() is deliberately not used to work around a breaking change introduced + // in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned). + var application = await Applications.AsQueryable() + .FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken); + if (application == null) { throw new InvalidOperationException("The application associated with the token cannot be found."); @@ -955,7 +961,13 @@ namespace OpenIddict.EntityFrameworkCore if (!string.IsNullOrEmpty(identifier)) { - var authorization = await Authorizations.FindAsync(new object[] { ConvertIdentifierFromString(identifier) }, cancellationToken); + var key = ConvertIdentifierFromString(identifier); + + // Warning: FindAsync() is deliberately not used to work around a breaking change introduced + // in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned). + var authorization = await Authorizations.AsQueryable() + .FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken); + if (authorization == null) { throw new InvalidOperationException("The authorization associated with the token cannot be found.");