entity-framework - 如何更改表的 Identity Server 4 架构?

标签 entity-framework asp.net-core

默认情况下,Identity Server 4 的表架构是 dbo,我想将其更改为安全性,因此我创建了继承自 ConfigurationDbContextConfigurationContext >:

 public class ConfigurationContext : ConfigurationDbContext
 {
    public ConfigurationContext(DbContextOptions<ConfigurationDbContext> options, ConfigurationStoreOptions storeOptions) : base(options, storeOptions)
    { }


    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.HasDefaultSchema("Security");
    }
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        var relationalOptions = RelationalOptionsExtension.Extract(optionsBuilder.Options);
        relationalOptions.MigrationsHistoryTableSchema = "Security";
    }

  }

add-migration 中我使用 ConfigurationContext :

Add-Migration -c ConfigurationContext

但是我得到了这个错误:

No parameterless constructor was found on 'ConfigurationContext'. Either add a parameterless constructor to 'ConfigurationContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'ConfigurationContext'.

问题是什么?

最佳答案

IdentityServer4 提供了这个选项。在 ConfigureServices 中,

services.AddIdentityServer()
.AddOperationalStore(builder => builder.UseSqlServer(cnStr, options =>
                        options.MigrationsAssembly(migAssembly)),
                        storeOption => storeOption.DefaultSchema = "security")

这样,您就可以按照快速入门中的建议继续使用 IDbContextFactory

关于entity-framework - 如何更改表的 Identity Server 4 架构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42276628/

相关文章:

sql-server - SQL Azure - 登录后阶段超时时间已过

asp.net-mvc - 在单个事务上包装成员资格提供程序和 dbcontext

entity-framework - 使用单独的文件来维护 Entity Framework 的连接字符串

azure - ASP.NET Core Docker 容器内的 Nginx

c# - 如何使用 asp.net core/react 发布数据

c# - ASP.NET Core Route Tag Helper 使用 Route?

asp.net-core - Fluent 验证在 Bootstrap 4 Modal 中不起作用

c# - 忽略复杂类型的一个属性

c# - 如何使用 Entity Framework 保证代码与派生字段一致

c# - ASP.NET CORE, View 模型在传回 Controller 时所有字段都为空