【问题标题】:Entitiy Framework migration with EF in multiple projects在多个项目中使用 EF 迁移实体框架
【发布时间】:2015-08-25 20:28:58
【问题描述】:

目前我试图将我的数据模型分离到同一个解决方案中的不同项目中,首先使用代码。如果我只有一个安装了 EF(6.1.3) 的项目,迁移 (Enable-Migration, Add-Migration) 将按预期工作。

但是当我添加另一个项目并安装 EF 数据包时,如果我尝试Enable-Migration,我会收到此错误:

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:713 char:27
+     $toolsPath = Join-Path <<<<  $installPath tools
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 char:73
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path <<<<  $ToolsPath EntityFramework.PowerShell.Utility.dll))
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

You cannot call a method on a null-valued expression.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 char:50
+     $dispatcher = $utilityAssembly.CreateInstance <<<< (
    + CategoryInfo          : InvalidOperation: (CreateInstance:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:810 char:19
+         (Join-Path <<<<  $runner.ToolsPath EntityFramework.PowerShell.dll),
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

EF 似乎在这两个项目中都运行良好。将 EF 重新安装到其中一个或两个项目并没有解决它。有什么解决方案吗?

编辑:我用 3 个项目开始了一个新的解决方案,1. 用于基本上下文(public class BaseContext&lt;TContext&gt; : DbContext where TContext : DbContext ...),2. 用于基类,3. 用于基于基本上下文和类创建上下文。如果我只将 ef 放入一个中,那么迁移工作,或者至少告诉我它找不到上下文,但如果我将它安装到多个中,那么它会再次产生错误。

【问题讨论】:

    标签: entity-framework powershell model-view-controller database-migration


    【解决方案1】:

    我今天发现同样的问题,我不得不卸载 EF 并重新安装。

    PM> 卸载包EntityFramework -Force

    PM> Install-Package EntityFramework -Pre

    【讨论】:

    • 我曾尝试重新安装,但效果不佳。我也没有找到任何参考,但 -Pre 并不意味着您安装了预发布包?目前是 7.0.something。我也开始怀疑,因为我的项目之一是 MVC 项目,具有身份,基于 EF,一些预配置的值会杀死 EF 迁移。
    【解决方案2】:

    好的,解决了,问题不是 EF 或 VS2015,而是我的 Windows 7,因为它带有 PowerShell 2,但 EF 或 VS 需要 PowerShell 3 才能正常工作。更新到它之后,错误消失了。

    然后我运行它来解决这个错误:https://connect.microsoft.com/VisualStudio/feedback/details/1302181/add-migration-bug 目前正在审查中。

    这似乎是由 VS2015 RC 版本中的一些配置错误引起的。使用powershell 2回滚到VS13,重新安装了相关的nuget包,现在可以正常使用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-09
      • 2015-07-20
      • 1970-01-01
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多