在通过nuget下载EF6并尝试运行我的项目后,它返回以下错误:

没有为ADO找到实体框架提供程序。NET提供程序,使用不变名称'System.Data.SqlClient'。确保提供者在应用程序配置文件的“entityFramework”部分中注册。更多信息请参见http://go.microsoft.com/fwlink/?LinkId=260882。


当前回答

只需安装EntityFramework包到您的Web/控制台项目。这应该会将该节添加到配置文件中。

其他回答

将以下内容添加到app.config中。

 <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

而不是添加EntityFramework。您可以确保从模型/实体项目中对它进行静态引用,如下所示

static MyContext()
{
    var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
    if(type == null)
        throw new Exception("Do not remove, ensures static reference to System.Data.Entity.SqlServer");
}

这将使构建过程将程序集与主机项目包括在一起。

更多信息在我的博客上 http://andersmalmgren.com/2014/08/20/implicit-dependencies-and-copy-local-fails-to-copy/

您已经将EF添加到类库项目中。你还需要将它添加到引用它的项目(你的控制台应用程序,网站或任何东西)。

似乎没有人提到首先检查system . data . sqlclient是否安装在系统中,以及是否引用了它。

我通过安装System.Data.SqlClient并在app.Config中添加一个新的提供者来解决我的问题

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>

另外,确保你的启动项目是包含dbcontext(或相关的app.config)的项目。我的是试图启动一个网站项目,没有所有必要的配置设置。