diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs index 8a91f158..4e26e1c5 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs @@ -161,14 +161,26 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(application)); } + // Note: due to a bug in Entity Framework Core's query visitor, the authorizations can't be + // filtered using authorization.Application.Id.Equals(key). To work around this issue, + // this local method uses an explicit join before applying the equality check. + // See https://github.com/openiddict/openiddict-core/issues/499 for more information. + Task> ListAuthorizationsAsync() => (from authorization in Authorizations.Include(authorization => authorization.Tokens) - where authorization.Application.Id.Equals(application.Id) + join element in Applications on authorization.Application.Id equals element.Id + where element.Id.Equals(application.Id) select authorization).ToListAsync(cancellationToken); + // Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be + // filtered using token.Application.Id.Equals(key). To work around this issue, + // this local method uses an explicit join before applying the equality check. + // See https://github.com/openiddict/openiddict-core/issues/499 for more information. + Task> ListTokensAsync() => (from token in Tokens - where token.Application.Id.Equals(application.Id) + join element in Applications on token.Application.Id equals element.Id + where element.Id.Equals(application.Id) select token).ToListAsync(cancellationToken); // Remove all the authorizations associated with the application and diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs index dfe15ba3..ea2b2b20 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs @@ -161,9 +161,15 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(authorization)); } + // Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be + // filtered using token.Application.Id.Equals(key). To work around this issue, + // this local method uses an explicit join before applying the equality check. + // See https://github.com/openiddict/openiddict-core/issues/499 for more information. + Task> ListTokensAsync() => (from token in Tokens - where token.Authorization.Id.Equals(authorization.Id) + join element in Authorizations on token.Authorization.Id equals element.Id + where element.Id.Equals(authorization.Id) select token).ToListAsync(cancellationToken); // Remove all the tokens associated with the application.