【发布时间】:2020-12-13 13:17:26
【问题描述】:
我正在尝试在使用 IdentityServer 进行身份验证的 ASP Core API 项目中利用 AddDBContextPool。问题是,要使用 PersistedGrants,您需要以这种方式设置 DBContext:
private readonly IOptions<OperationalStoreOptions> _operationalStoreOptions;
public ApplicationDbContext(
DbContextOptions options,
IOptions<OperationalStoreOptions> operationalStoreOptions) : base(options)
{
_operationalStoreOptions = operationalStoreOptions;
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ConfigurePersistedGrantContext(_operationalStoreOptions.Value);
}
AddDBContextPool 只需要一个仅将 DbContextOptions 作为参数的构造函数。所以我不能再注入operationalStoreOptions了。
我尝试使用 Startup 类中的 AddOperationalStore(),但出现以下错误:
实体类型“DeviceFlowCodes”需要一个主键 定义。如果您打算使用无键实体类型调用 'HasNoKey()'。
知道我错过了什么吗?
【问题讨论】:
-
这是link,你可以看到Stevegreatrex说
Looks like ApiAuthorizationDbContext specifies a primary key for DeviceFlowCodes (and other types) which - by overriding - I had removed. Add base.OnModelCreating(modelBuilder) to the top of the method and everything starts working again -
谢谢依依。我确实看到了这个链接,但不幸的是我已经调用了 base.OnModelCreating()。不过还是不行。
标签: asp.net-core identityserver4