Asp.net mvc 如何将实体框架迁移添加到不同于具有上下文的项目?

Asp.net mvc 如何将实体框架迁移添加到不同于具有上下文的项目?,asp.net-mvc,entity-framework,Asp.net Mvc,Entity Framework,在project MyProject.DAL中,我有databasecontext。我想将实体框架迁移添加到project MyProject。迁移,因此我在控制台中编写: Enable-Migrations -ProjectName MyProject.Migrations -StartUpProjectName MyProject.DAL 但我有一个错误: 在程序集“MyProject.Migrations”中未找到上下文类型。 为什么?所以我知道这个问题已经问了很长时间了,但是,我遇到了

在project MyProject.DAL中,我有databasecontext。我想将实体框架迁移添加到project MyProject。迁移,因此我在控制台中编写:

Enable-Migrations -ProjectName MyProject.Migrations -StartUpProjectName MyProject.DAL
但我有一个错误:

在程序集“MyProject.Migrations”中未找到上下文类型。


为什么?

所以我知道这个问题已经问了很长时间了,但是,我遇到了类似的情况,并设法找到了答案

作为参考,请看一看

可以归结为这种语法:

Enable-Migrations -ProjectName <Project Name> -ContextTypeName <Context Type Name including Namespace>
Update-Database -ProjectName <Project Name> -configuration <Namespace>.Migrations.Configuration -TargetMigration $InitialDatabase
Add-Migration -ProjectName <Project Name> -configuration <Namespace>.Migrations.Configuration Init -Force
Update-Database -ProjectName  <Project Name> -configuration <Namespace>.Migrations.Configuration
启用迁移-ProjectName-ContextTypeName
更新数据库-ProjectName-configuration.Migrations.configuration-TargetMigration$InitialDatabase
添加Migration-ProjectName-configuration.Migrations.configuration Init-Force
更新数据库-ProjectName-configuration.Migrations.configuration
我希望这对某人有帮助