我遇到了同样的问题,而且在寻找解决方案时发现了你的问题。
我解决了这个问题。对我来说,问题是我最初通过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>
所以我做的是在解决方案配置中将目标框架设置为4.5,并在应用程序配置中将支持的运行时也设置为4.5。
旧:
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
新的内容:
<startup>
<supportedRuntime version="v4.5" sku=".NETFramework,Version=v4.5" />
</startup>
在此更改后,我通过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>
修改后,它能正常工作了。