IConfigurationDbContext 返回缺少的列
IConfigurationDbContext returning missing columns
我正在尝试在我的身份服务器上搜索有效的客户端。它当前正在运行 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 migrations add updatedIdentityServer4Schema
它导致了以下错误:
An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: Den angivne sti blev ikke fundet
More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.
注:
dotnet ef migrations add updatedIdentityServer4Schema -c ConfigurationDbContext
'ConfigurationDbContext' 上未找到无参数构造函数。将无参数构造函数添加到 'ConfigurationDbContext' 或在与 'ConfigurationDbContext'.
相同的程序集中添加 'IDbContextFactory' 的实现
更新 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 migrations add updatedIdentityServer4Schema -c ConfigurationDbContext
An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: Den angivne sti blev ikke fundet
Executed DbCommand (47ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'__EFMigrationsHistory');
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'__EFMigrationsHistory');
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
Applying migration '20171201112112_updatedIdentityServer4Schema'.
Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20171201112112_updatedIdentityServer4Schema', N'1.1.2');
Done.
之后我进行了更新。但是新的列还没有出现在我的数据库中。
一旦完整的身份服务器项目升级到 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 更新到最新版本的数据库。我建议修复上面的代码以使用它当前不执行的配置文件。
我正在尝试在我的身份服务器上搜索有效的客户端。它当前正在运行 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 migrations add updatedIdentityServer4Schema
它导致了以下错误:
An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: Den angivne sti blev ikke fundet More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.
注:
dotnet ef migrations add updatedIdentityServer4Schema -c ConfigurationDbContext
'ConfigurationDbContext' 上未找到无参数构造函数。将无参数构造函数添加到 'ConfigurationDbContext' 或在与 'ConfigurationDbContext'.
相同的程序集中添加 'IDbContextFactory' 的实现更新 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 migrations add updatedIdentityServer4Schema -c ConfigurationDbContext
An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: Den angivne sti blev ikke fundet Executed DbCommand (47ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'__EFMigrationsHistory'); Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'__EFMigrationsHistory'); Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [MigrationId], [ProductVersion] FROM [__EFMigrationsHistory] ORDER BY [MigrationId]; Applying migration '20171201112112_updatedIdentityServer4Schema'. Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) VALUES (N'20171201112112_updatedIdentityServer4Schema', N'1.1.2'); Done.
之后我进行了更新。但是新的列还没有出现在我的数据库中。
一旦完整的身份服务器项目升级到 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 更新到最新版本的数据库。我建议修复上面的代码以使用它当前不执行的配置文件。