entity-framework-6 - 启用迁移不适用于具有现有数据库配置的项目

标签 entity-framework-6 entity-framework-migrations

我正在尝试在具有现有数据库配置的解决方案中运行 Enable-Migrations cmd-let,但无论我尝试哪种选项组合,我都会收到以下错误:

Exception calling "LoadFrom" with "1" argument(s): "Invalid directory on URL."
At my-project\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 char:5
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path $ToolsP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException

You cannot call a method on a null-valued expression.
At my-project\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 char:5
+     $dispatcher = $utilityAssembly.CreateInstance(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "CreateInstanceFrom" with "8" argument(s): "Invalid directory on URL."
At my-project\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:809 char:5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException

解决方案的结构如下:

Foo.sln
┖─ DbCreator (command line program, transfers data from an old db)
┖─ Foo.Api (WebAPI project, default startup project)
┖─ Foo.Repository (Contains entities and DbContext)
┖─ other utility and test projects

我想做的是查看 Foo.Repository 中的 DbContext(解决方案中唯一的一个),并允许迁移到 DbCreator 项目,因此我可以在每次运行 exe 时运行迁移。

我正在使用 VS 2015 和 EF 6.1.3。

最佳答案

这是一个已知问题,解决方法请查看 1950#issue

关于entity-framework-6 - 启用迁移不适用于具有现有数据库配置的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31286966/

相关文章:

entity-framework - 如何按照约定首先删除代码中外键字段的下划线

azure - 使用 Entity Framework 将 Web api 部署到 Azure,工作了 1 小时,现在出现错误 500

entity-framework - 如何在 Entity Framework 迁移中使用多对五关系播种数据

c# - Azure 持续部署 - Code First 迁移播种问题 (MVC 5)

c# - 在迁移 Up 方法中更改数据 - Entity Framework

entity-framework - DbMigrator 尝试执行每个迁移,而不是检测已执行的迁移

c# - 无法确定类型为 "System.Data.Sqlite.SqliteFactory"的提供程序工厂的提供程序名称

c# - 使用 Entity Framework 从数据库中添加和删除数据

.net - Entity Framework 是否支持并行异步查询?

c# - 如何使用 EF 迁移将 int ID 列更改为 Guid?