我正在尝试在我的身份服务器上搜索有效的客户端。它目前正在运行的identityserver4。
我的代码:
// GET api/developerconsole/{clientId}
[HttpGet("{clientId}")]
public async Task<ActionResult> Get(string clientId)
{
try
{
var client = _configurationDbContext.Clients.Find(1); // Fails here
return Ok(Newtonsoft.Json.JsonConvert.SerializeObject(client));
}
catch (Exception ex)
{
return BadRequest(ex);
}
}
错误
Invalid column name 'BackChannelLogoutSessionRequired'.
Invalid column name 'BackChannelLogoutUri'.
Invalid column name 'ClientClaimsPrefix'.
Invalid column name 'ConsentLifetime'.
Invalid column name 'Description'.
Invalid column name 'FrontChannelLogoutSessionRequired'.
Invalid column name 'FrontChannelLogoutUri'.
Invalid column name 'PairWiseSubjectSalt'.
ConfigurationDbContext注入
// IDS
services.AddEntityFrameworkSqlServer()
.AddDbContext<ConfigurationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("XenaIdentityConnection")));
我不明白为什么它会缺少列
更新
正如我在评论中所建议的那样
dotnet ef迁移添加updatedIdentityServer4Schema
导致以下错误:
调用方法&#39; ConfigureServices&#39;时发生错误在创业班&#39; Startup&#39;。考虑使用IDbContextFactory在设计时覆盖DbContext的初始化。错误:Den angivne sti blev ikke fundet 找到了多个DbContext。指定要使用的那个。使用&#39; -Context&#39; PowerShell命令的参数和&#39; - context&#39; dotnet命令的参数。
注意:
dotnet ef迁移添加updatedIdentityServer4Schema -c ConfigurationDbContext
在ConfigurationDbContext&#39;上找不到无参数构造函数。将无参数构造函数添加到&#39; ConfigurationDbContext&#39;或者添加&#39; IDbContextFactory&#39;的实现在与ConfigurationDbContext&#39;。
相同的程序集中更新2:
项目中的代码似乎应支持使用此Using EntityFramework Core for configuration and operational data
进行迁移我能看到的唯一区别是我们从另一个数据库请求我们的用户数据
services.AddDbContext<UserDbContext>(builder =>builder.UseSqlServer(Configuration.GetConnectionString("ConnectionToUserDB")));
更新:
我尝试创建一个idbcontextfactory
public class ConfigurationFactory : IDbContextFactory<ConfigurationDbContext>
{
public ConfigurationDbContext Create(DbContextFactoryOptions options)
{
var connectionString = "server=.\\sqlexpress;initial catalog=Xena.Identity2.0;Integrated Security=true";
var optionsBuilder = new DbContextOptionsBuilder<ConfigurationDbContext>();
optionsBuilder.UseSqlServer(connectionString, b => b.MigrationsAssembly("Xena.IdentityServer"));
return new ConfigurationDbContext(optionsBuilder.Options, new ConfigurationStoreOptions());
}
}
这让我
dotnet ef迁移添加updatedIdentityServer4Schema -c ConfigurationDbContext
调用方法&#39; ConfigureServices&#39;时发生错误在创业班&#39; Startup&#39;。考虑使用IDbContextFactory在设计时覆盖DbContext的初始化。错误:Den angivne sti blev ikke fundet 执行DbCommand(47ms)[Parameters = [],CommandType =&#39; Text&#39;,CommandTimeout =&#39; 30&#39;] SELECT OBJECT_ID(N&#39; __ EFMigrationsHistory&#39;); 执行DbCommand(2ms)[Parameters = [],CommandType =&#39; Text&#39;,CommandTimeout =&#39; 30&#39;] SELECT OBJECT_ID(N&#39; __ EFMigrationsHistory&#39;); 执行DbCommand(2ms)[Parameters = [],CommandType =&#39; Text&#39;,CommandTimeout =&#39; 30&#39;] SELECT [MigrationId],[ProductVersion] FROM [__EFMigrationsHistory] ORDER BY [MigrationId]; 应用迁移&#39; 20171201112112_updatedIdentityServer4Schema&#39;。 执行DbCommand(7ms)[Parameters = [],CommandType =&#39; Text&#39;,CommandTimeout =&#39; 30&#39;] INSERT INTO [__EFMigrationsHistory]([MigrationId],[ProductVersion]) 价值观(N&#39; 20171201112112_updatedIdentityServer4Schema&#39;,N&#39; 1.1.2&#39;); 完成。
之后我做了更新。但是新列没有出现在我的数据库中。
答案 0 :(得分:3)
完整的Identity Server项目升级到2.0后。并构建了IdentityServer4 2.0中的一些重大变化
我添加了以下内容
public class ConfigurationFactory : IDesignTimeDbContextFactory<ConfigurationDbContext>
{
public ConfigurationDbContext CreateDbContext(string[] args)
{
var connectionString = "server=.\\sqlexpress;initial catalog=Xena.Identity2.0;Integrated Security=true";
var optionsBuilder = new DbContextOptionsBuilder<ConfigurationDbContext>();
optionsBuilder.UseSqlServer(connectionString, b => b.MigrationsAssembly("Xena.IdentityServer"));
return new ConfigurationDbContext(optionsBuilder.Options, new ConfigurationStoreOptions());
}
}
public class PersistedGrantDbContextFactory : IDesignTimeDbContextFactory<PersistedGrantDbContext>
{
public PersistedGrantDbContext CreateDbContext(string[] args)
{
var connectionString = "server=.\\sqlexpress;initial catalog=Xena.Identity2.0;Integrated Security=true";
var optionsBuilder = new DbContextOptionsBuilder<PersistedGrantDbContext>();
optionsBuilder.UseSqlServer(connectionString, b => b.MigrationsAssembly("Xena.IdentityServer"));
return new PersistedGrantDbContext(optionsBuilder.Options, new OperationalStoreOptions());
}
}
然后我能够预成型
dotnet ef migrations add updatedIdentityServer4Schema -c ConfigurationDbContext
dotnet ef database update -c ConfigurationDbContext
dotnet ef migrations add updatedIdentityServer4Schema -c
PersistedGrantDbContext
dotnet ef database update -c PersistedGrantDbContext
更新为IdentityServer4的最新版数据库。我建议修复上面的代码以使用它当前没有做的配置文件。