How do I specify a schema for IdentityServer4 Entity Framework Core Migrations?(如何为标识服务器4实体框架核心迁移指定架构?)
问题描述
我使用的是IdentityServer4 2.0.2,并遵循QuickStart tutorial使用了实体框架核心。我正在尝试从默认架构(Dbo)更改为SQL Server中的自定义架构。以下代码工作正常,指示DbContext在"idsrv4"架构中查找表。
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var identityConnectionString = Configuration.GetConnectionString("Identity");
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddTestUsers(Config.GetUsers())
.AddConfigurationStore(options =>
{
options.DefaultSchema = "idsrv4";
options.ConfigureDbContext = builder => builder.UseSqlServer(identityConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.DefaultSchema = "idsrv4";
options.ConfigureDbContext = builder => builder.UseSqlServer(identityConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
});
}
在我的开发环境中,我使用以下代码从Startup.cs中的configuration()方法初始化数据库:
var context = serviceScope.ServiceProvider.GetRequiredService<ConfigurationDbContext>();
context.Database.Migrate();
问题是表仍在dbo模式中创建。如何指示Migrate()方法(来自Microsoft.EntityFrameworkCore)使用我提供的架构?
推荐答案
我是如何让它在.Net Core1.1和标识服务器4 1.x上工作的
将我的配置部分添加到appsettings.json。
"IdentityServerConfig": {
"DBConfig": {
"IdentityServer": "Data Source=dbservername.database.windows.net;User ID=user_Name;Password=password;Initial Catalog=DBNAme;",
"DefaultSchema": "IDSVR"
},
"CertificateConfig": {
"Thumbprint": "",
"FileName": "cert.pfx",
"SubDirectory": "",
"PassPhrase": "password"
},
"RaiseErrorEvents": true,
"RaiseFailureEvents": true,
"RaiseInformationEvents": true,
"RaiseSuccessEvents": true
}
为标识服务器的配置设置创建了一个类。
public class IdentityServerConfig
{
public CertificateConfig CertificateConfig { get; set; }
public DBConfig DBConfig { get; set; }
public bool RaiseErrorEvents { get; set; }
public bool RaiseFailureEvents { get; set; }
public bool RaiseInformationEvents { get; set; }
public bool RaiseSuccessEvents { get; set; }
}
public void ConfigureServices(IServiceCollection services)
{
...Other Code
var identityServerConfig = config.GetSection("IdentityServerConfig").Get<IdentityServerConfig>();
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = identityServerConfig.RaiseErrorEvents ;
options.Events.RaiseFailureEvents = identityServerConfig.RaiseFailureEvents ;
options.Events.RaiseInformationEvents = identityServerConfig.RaiseInformationEvents ;
options.Events.RaiseSuccessEvents = identityServerConfig.RaiseSuccessEvents ;
})
.AddConfigurationStore(
b => b.UseSqlServer(identityServerConfig.DBConfig.IdentityServer ,
options =>
{
options.MigrationsAssembly(migrationsAssembly);
}), storeOption =>
{
storeOption.DefaultSchema = identityServerConfig.DBConfig.DefaultSchema ;//IDSVR
})
.AddOperationalStore(
b => b.UseSqlServer(identityServerConfig.DBConfig.IdentityServer,
options => options.MigrationsAssembly(migrationsAssembly)
), storeOption => storeOption.DefaultSchema = identityServerConfig.DBConfig.DefaultSchema //IDSVR
);
}
这篇关于如何为标识服务器4实体框架核心迁移指定架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为标识服务器4实体框架核心迁移指定架构?


基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01