升级到.NET 4.5和EF 5后,"启用 - 迁移"失败

Dan*_*Dan 14 asp.net-mvc-4 .net-4.5 entity-framework-5

我刚刚将我的MVC4项目升级到.NET 4.5和EF5并开始使用VS2012.在意识到我需要再次在程序包管理器中设置自动迁移后,我运行Enable-Migrations - EnableAutomaticMigrations并收到错误

No context type was found in the assembly 'MySolutionName'.

一些研究表示,它与EF5有关,不支持预发布.我跑了,Install-Package EntityFramework -IncludePrerelease但它说已经安装了EF5(当我之前通过NuGetmanager安装它时没有指定-IncludePrerelease.

有谁知道我必须做什么才能为我的项目启用迁移?

Roe*_*oet 15

我遇到了同样的问题,在寻找解决方案时发现了你的问题.

我搞定了.对我来说,问题是当我通过NuGet添加EF 5时,我最初的目标是.NET 4.0框架.更改目标框架,然后通过NuGet重新安装EF 5,修复它.也可以(参见评论)通过NuGet重新安装EF 5是您的解决方案.

我在App.config文件中有以下行,注意Version = 4.4.0.0:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
</configuration>
Run Code Online (Sandbox Code Playgroud)

所以我所做的是在解决方案配置中将目标框架设置为4.5,并将支持的运行时也设置为4.5(在app config中).

旧:

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
Run Code Online (Sandbox Code Playgroud)

新:

  <startup>
    <supportedRuntime version="v4.5" sku=".NETFramework,Version=v4.5" />
  </startup>
Run Code Online (Sandbox Code Playgroud)

在更改之后,我通过NuGet删除了EF 5.0并再次添加.它给了我以下的configSection作为结果,注意Version = 5.0.0.0:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
</configuration>
Run Code Online (Sandbox Code Playgroud)

在那次改变之后,它奏效了.

  • 我最终卸载了EntityFramework,通过Nuget,然后重新安装,配置文件"自行修复". (5认同)