Skip to content

Commit 76cea94

Browse files
committed
Backport the Entity Framework Core workaround to OpenIddict 1.x
2 parents 8318f2d + 57676d7 commit 76cea94

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,26 @@ public override async Task DeleteAsync([NotNull] TApplication application, Cance
161161
throw new ArgumentNullException(nameof(application));
162162
}
163163

164+
// Note: due to a bug in Entity Framework Core's query visitor, the authorizations can't be
165+
// filtered using authorization.Application.Id.Equals(key). To work around this issue,
166+
// this local method uses an explicit join before applying the equality check.
167+
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
168+
164169
Task<List<TAuthorization>> ListAuthorizationsAsync()
165170
=> (from authorization in Authorizations.Include(authorization => authorization.Tokens)
166-
where authorization.Application.Id.Equals(application.Id)
171+
join element in Applications on authorization.Application.Id equals element.Id
172+
where element.Id.Equals(application.Id)
167173
select authorization).ToListAsync(cancellationToken);
168174

175+
// Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be
176+
// filtered using token.Application.Id.Equals(key). To work around this issue,
177+
// this local method uses an explicit join before applying the equality check.
178+
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
179+
169180
Task<List<TToken>> ListTokensAsync()
170181
=> (from token in Tokens
171-
where token.Application.Id.Equals(application.Id)
182+
join element in Applications on token.Application.Id equals element.Id
183+
where element.Id.Equals(application.Id)
172184
select token).ToListAsync(cancellationToken);
173185

174186
// Remove all the authorizations associated with the application and

src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,15 @@ public override async Task DeleteAsync([NotNull] TAuthorization authorization, C
161161
throw new ArgumentNullException(nameof(authorization));
162162
}
163163

164+
// Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be
165+
// filtered using token.Application.Id.Equals(key). To work around this issue,
166+
// this local method uses an explicit join before applying the equality check.
167+
// See https://github.com/openiddict/openiddict-core/issues/499 for more information.
168+
164169
Task<List<TToken>> ListTokensAsync()
165170
=> (from token in Tokens
166-
where token.Authorization.Id.Equals(authorization.Id)
171+
join element in Authorizations on token.Authorization.Id equals element.Id
172+
where element.Id.Equals(authorization.Id)
167173
select token).ToListAsync(cancellationToken);
168174

169175
// Remove all the tokens associated with the application.

0 commit comments

Comments
 (0)