C# 如何使用PersistedGrandDBContext选择PersistedGrant

C# 如何使用PersistedGrandDBContext选择PersistedGrant,c#,asp.net,.net,asp.net-core,identityserver4,C#,Asp.net,.net,Asp.net Core,Identityserver4,我希望获得如下数据: var persistedGrants = await _PersistedGrantDbContext.PersistedGrants.ToListAsync(); 这是我的配置: services.AddDbContext<AccountDbContext>(options => options.UseSqlServer(connectionString,

我希望获得如下数据:

var persistedGrants = await _PersistedGrantDbContext.PersistedGrants.ToListAsync();
这是我的配置:

services.AddDbContext<AccountDbContext>(options =>
                        options.UseSqlServer(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly)))
                    .AddDbContext<PersistedGrantDbContext>(options =>
                        options.UseSqlServer(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly)));
但我有一个错误:

处理请求时发生未处理的异常。 InvalidOperationException:无法解析类型的服务 'IdentityServer4.EntityFramework.Options.OperationalStoreOptions' 试图激活时 “IdentityServer4.EntityFramework.DbContexts.PersistedGrantDbContext”


我应该怎么解决它呢?

不需要直接调用数据库,而是使用提供的存储

在这种情况下,您可以使用IPersistedGrantStore:


是的,我已经解决了我的问题。我错过了服务。AddIdentityServer.AddOperationalStore

是的,我已经解决了我的问题。我错过了services.AddIdentityServer.addStore。我必须使用PersistedGrandDBContext来获取PersistedGrants表中的所有数据。谢谢
public class MyClass
{
    private readonly IPersistedGrantStore _store;

    public MyClass(IPersistedGrantStore store)
    {
        _store = store;
    }

    public async Task Something(string sub)
    {
        var persistedGrants = await _store.GetAllAsync(sub);
    }

}