无法检索无法识别的元素提供程序的元数据

时间:2014-01-22 14:17:55

标签: entity-framework asp.net-mvc-4 ef-code-first database-connection connection-string

每当我尝试添加带有Entity框架模板的控制器时,我都会收到一条消息错误,但我一直收到错误消息

    unable to retrieve metadata for 'path' unrecognized element providers. 
         (C:\Users\user\appdata\local\Temp-mp6124.tmp line 78)

我知道它与连接字符串有关,所以这是我的连接字符串

  <connectionStrings>
    <add name="NoktatyContext" connectionString="Data Source=(localdb)\v11.0; Initial Catalog=NoktatyContext-20140122154208; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|NoktatyContext-20140122154208.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>

2 个答案:

答案 0 :(得分:43)

我能够通过删除配置文件的<providers>部分来解决此问题。

此:

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
</entityFramework>

成为这个:

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>

今天早上我遇到了这个问题,刚刚找到修复程序。如果您没有指定数据库(我猜测提供者),EF将默认为SQL Server Express。

答案 1 :(得分:3)

MVC脚手架不支持Entity Framework 6或更高版本

请取消当前版本的Entity Framework,与Install-Package EntityFramework -Version 5.0.0取消。

删除代码......

重启VS