从特定项目运行迁移

时间:2019-10-21 17:52:38

标签: c# asp.net .net asp.net-core

我有3个解决方案的项目。

这是它的样子

enter image description here

我的迁移在COMMENT

在TooSeeWeb下的TooSeeWeb.Infrastructure中,我有此代码

Startup.cs

这是ApplicationDbContext代码

 services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection"),
                b => b.MigrationsAssembly("TooSeeWeb.Infrastructure")));

但是在 public class ApplicationDbContext : IdentityDbContext<AppUser> { public ApplicationDbContext( DbContextOptions<ApplicationDbContext> options) : base(options) { } public DbSet<Experience> Experiences { get; set; } public DbSet<Proposals> Proposals { get; set; } public DbSet<Comments> Comments { get; set; } public DbSet<Country> Countries { get; set; } public DbSet<AppUser> IdentityUsers { get; set; } public DbSet<TermsOfUse> TermsOfUse { get; set; } public DbSet<Privacy> Privacy { get; set; } public DbSet<IdentityUserClaim<string>> IdentityUserClaims { get; set; } public DbSet<BookmarkFolder> BookmarkFolders { get; set; } } 中运行TooSeeWeb.Infrastructure时出现此错误

  

无法创建类型为“ ApplicationDbContext”的对象。有关设计时支持的不同模式,请参见https://go.microsoft.com/fwlink/?linkid=851728

但是当我运行dotnet ef database update时一切正常。

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您真的必须使用IdentityDbContext吗?如果没有,请使用DbContext并重写OnConfiguring方法,以便您可以按以下方式声明连接字符串:

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseSqlServer("connectionString");
        }
    }
}