0
我在我的解决方案中有两个项目,他们都参考相同的数据库。 使用ASP.NET Core EF &标识我连接到同一个数据库以存储所有IdentityServer信息。实体框架 - 两个项目,相同的数据库
项目IdentityServer
namespace IdentityServer.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{}
}
}
项目IdentityServerBackOffice
namespace IdentityServerBackOffice.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{}
public DbSet<PasswordPolicy> PasswordPolicy { get; set; }
public DbSet<PasswordHistory> PasswordHistory { get; set; }
}
}
当我要生成使用EF数据库中,我得到一些表存在错误,因为他们是由第一数据库 - 创建更新
生成IdentityServer的迁移+数据库
dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb
dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
dotnet ef migrations add InitialIdentityServerIdentity -c ApplicationDbContext -o Data/Migrations/IdentityServer/Identity
dotnet ef database update -c ApplicationDbContext
生成迁移+数据库为IdentityServer
dotnet ef migrations add InitialIdentityServerIdentity -c ApplicationDbContext -o Data/Migrations/IdentityServerBackOffice/Identity
dotnet ef database update -c ApplicationDbContext
有双方共享了一些常见的表,一些具体的创建IdentityServer和其他一些用于IdentityServerBackOffice,我怎么能忽略一些创作表?或者任何其他建议,以便我可以拥有所有我需要的表格的数据库?
我无法控制DbSets for Identity,它是一个导入的库。我只能像我为PasswordPolicy和PasswordHistory那样添加新的。 –
你有什么理由在IdentityServerBackOffice中从IdentityDbContext扩展ApplicationDbContext?尝试从DbContext扩展,表已存在的问题是因为这一点。 –
在IdentityServerBackOffice(ISBO)中,我希望能够访问与IdentityServer相同的用户,所以是的。在我的理解中,我需要扩展它,以便可以在两个项目上查询相同的用户。 ISBO创建用户,IS访问那些用于登录目的的相同用户。 –