Equinox项目迁移数据库

时间:2019-03-12 10:46:13

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

我目前正在学习使用asp.net核心创建rest api。
我在GitHub上找到了一个项目,该项目实现了一些我感兴趣的技术。 https://github.com/EduardoPires/EquinoxProject

现在我正在尝试设置此项目。
我的主要问题是add migrationsupdate database

当我尝试Add-Migration init -Context EquinoxContext时,出现以下错误消息:

  

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

我找到了一个可行的解决方案,但我不认为这是可行的方法,因为该项目最初没有这样做。

我已经在startup.cs的{​​{1}}的ConfigureServices方法中添加了dbcontext文件

Equniox.Services.Api

如果我从项目文件中使用 services.AddDbContext<EquinoxContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Equinox.Infra.Data"))); services.AddDbContext<EventStoreSQLContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Equinox.Infra.Data"))); ,则该项目运行良好,但我想了解如何从代码库构建数据库。

还有其他命令来创建迁移然后更新数据库吗?

1 个答案:

答案 0 :(得分:0)

解决方案 更改 services.AddScoped <'EquinoxContext'>();通过  services.AddDbContext <'EquinoxContext'>();

Y services.AddScoped <'EventStoreSQLContext'>(); 通过 services.AddDbContext <'EventStoreSQLContext'>();

NativeInjectorBootStrapper.cs

控制台:

开始项目:Api

重点项目:数据