entity-framework - 无法为无法识别的元素提供者检索元数据

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

每当我尝试使用 Entity Framework 模板添加 Controller 时,我都会收到一条消息错误,但我一直收到错误消息

    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>

最佳答案

我可以通过删除配置文件的<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。

关于entity-framework - 无法为无法识别的元素提供者检索元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21285384/

相关文章:

c# - 获取 List<T> 中变量的 List<string>

c# - ASP.NET MVC 4,EF5,模型中的唯一属性 - 最佳实践?

c# - 使用 EF 检查表中新记录的成本最低的操作

c# - EDMX 从数据库更新模型超时

c# - 从查询字符串开始时比较 EntitySQL 中的 DateTime 值

c# - ASP.Net MVC 项目中的 "Main"方法 - 也就是在加载页面之前运行的方法?

asp.net-mvc-4 - Kendo UI 组合框重置值

c# - EF Code First,从多对多关系中公开链接表/对象?

c# - 带有 ViewModel 和两个表单的页面上的 "The anti-forgery cookie token and form field token do not match"

asp.net-mvc - 如何在ASP.NET MVC应用程序区域中使用不同的 Entity Framework DbContext?