我目前正在学习用asp.net核心创建rest api。 我在GitHub上找到了一个项目,它实现了一些我感兴趣的技术.https://github.com/EduardoPires/EquinoxProject
现在我正在尝试设置这个项目。
我的主要问题是add migrations
或update database
。
当我尝试Add-Migration init -Context EquinoxContext
时,我收到此错误消息:
无法创建“EquinoxContext”类型的对象。有关设计时支持的不同模式,请参阅https://go.microsoft.com/fwlink/?linkid=851728
我找到了一个有效的解决方案,但我认为这是要走的路,因为该项目最初并没有这样做。
我在startup.cs
的Equniox.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
项目运行良好,但我想了解如何从代码库构建数据库。
是否有其他命令来创建迁移然后更新数据库?
解决方案更改services.AddScoped <'EquinoxContext'>(); by services.AddDbContext <'EquinoxContext'>();
Y services.AddScoped <'EventStoreSQLContext'>(); by services.AddDbContext <'EventStoreSQLContext'>();
在
NativeInjectorBootStrapper.cs
安慰:
启动项目:Api
重点项目:数据