entity-framework - Entity Framework 代码第一次迁移抛出错误

标签 entity-framework c#-4.0 ef-code-first database-migration

这是我在出现此错误之前所做的:

  • 已安装 EF(预发布版本,可能是 6,我不知道)
  • 决定我不想要,所以卸载它并重新安装稳定版本 (5)
  • 通过 SSMS 截断我的数据库

  • 这是错误:
    Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or      
    assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicK
    eyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest   
    definition does not match the assembly reference. (Exception from H
    RESULT: 0x80131040)"
    At C:\Projects\BCATracker.Web\packages\EntityFramework.6.0.0- 
    alpha2\tools\EntityFramework.psm1:425 char:31
    +     $domain.CreateInstanceFrom <<<< (
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodTargetInvocation
    

    这是我尝试过的:
  • 从 bin 目录中删除所有内容,重建。
  • 从nuget中删除EF,删除packages目录中的文件,在nuget中读取ef。

  • 查看 proj 文件,我看到了这个:
    <Reference Include="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath>
    </Reference>
    

    可能的根本原因是什么?

    最佳答案

    我想通了这个问题。 EntityFramework.dll 需要在 GAC 中,Visual Studio 才能从包管理器中使用它。

  • 启动 Visual Studio 命令提示符(确保以管理员身份启动 Visual Studio)
  • 转到您的包目录并找到 EntityFramework 包目录。
  • 转到 lib\net45(如果目标是 4.5)
  • 类型:gacutil/i EntityFramework.dll

  • 注意:此时完全重新启动计算机可能是明智之举。

    我不确定为什么 Visual Studio 不再看到 DLL,但这让我解决了这个问题。

    关于entity-framework - Entity Framework 代码第一次迁移抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13832417/

    相关文章:

    entity-framework - 在 Entity Framework 6 C# 中获取特定迁移的 SQL 文件

    c# - 不声明外键的导航属性

    entity-framework - 在 postgres 中删除 SET NULL

    c# - 组合多个表达式树

    c# - 改进 LINQ 查询,使其完全在数据库中执行

    asp.net - 使用 DataView.RowFilter 过滤记录时转换列的数据类型

    javascript - 通过合并数据集到 JSON 树

    css - 2 种不同的 DataAnnotation 验证样式与 css

    ef-code-first - 多对多MVC 5模型代码首先连接表

    c# - 具有 ComplexType 的 BulkInsert 实体