如何将实体框架迁移添加到与具有上下文的项目不同的项目?

时间:2014-07-20 17:56:05

标签: asp.net-mvc entity-framework

在项目MyProject.DAL中,我有databasecontext。我想将实体框架迁移添加到项目MyProject.Migrations,所以我在控制台中写道:

Enable-Migrations -ProjectName MyProject.Migrations -StartUpProjectName MyProject.DAL

但我有错误:

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

为什么?

1 个答案:

答案 0 :(得分:0)

所以我知道自问这个问题以来已经有很长时间了,但是,我遇到了类似的情况并设法弄清了这一点。

作为参考,请看this link

它归结为这种语法:

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

我希望这对某人有帮助