diff --git a/Directory.Build.targets b/Directory.Build.targets
index 51c5ac51..91bb05f5 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -80,6 +80,7 @@
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '3.0'))) Or
('$(TargetFrameworkIdentifier)' == '.NETStandard' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '2.1'))) ">
$(DefineConstants);SUPPORTS_BCL_ASYNC_ENUMERABLE
+ $(DefineConstants);SUPPORTS_DBSET_VALUETASK_FINDASYNC
application.Id!.Equals(key), cancellationToken) ??
+ authorization.Application = GetTrackedEntity() ?? await QueryAsync() ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0244));
+
+ 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 Applications.AsTracking()
+ where application.Id!.Equals(key)
+ select application).FirstOrDefaultAsync(cancellationToken);
+#endif
}
else
diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs
index cf5920e8..4700ba07 100644
--- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs
+++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs
@@ -802,14 +802,27 @@ public class OpenIddictEntityFrameworkCoreTokenStore application.Id!.Equals(key), cancellationToken) ??
+ token.Application = GetTrackedEntity() ?? await QueryAsync() ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0250));
+
+ 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 Applications.AsTracking()
+ where application.Id!.Equals(key)
+ select application).FirstOrDefaultAsync(cancellationToken);
+#endif
}
else
@@ -840,14 +853,27 @@ public class OpenIddictEntityFrameworkCoreTokenStore authorization.Id!.Equals(key), cancellationToken) ??
+ token.Authorization = GetTrackedEntity() ?? await QueryAsync() ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0251));
+
+ 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 Authorizations.AsTracking()
+ where authorization.Id!.Equals(key)
+ select authorization).FirstOrDefaultAsync(cancellationToken);
+#endif
}
else