Equinox项目迁移数据库

问题描述 投票:0回答:1

我目前正在学习用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.csEquniox.Services.Api的ConfigureServices方法中添加了dbcontext文件

        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")));

如果我使用项目文件中的GenerateDataBase.sql项目运行良好,但我想了解如何从代码库构建数据库。

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

c# asp.net database asp.net-core
1个回答
0
投票

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

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

NativeInjectorBootStrapper.cs

安慰:

启动项目:Api

重点项目:数据

© www.soinside.com 2019 - 2024. All rights reserved.