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

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


当前回答

我今天才遇到这个问题。我有数据存储库类库与EF63 NuGet包和控制台应用程序进行测试,其中只引用类库项目。我创建了一个非常简单的构建后命令,它将EntityFramework.SqlServer.dll从类库的Bin\Debug文件夹复制到控制台应用程序的Bin\Debug文件夹,问题就解决了。不要忘记将entityFramework部分添加到控制台应用程序的.config文件中。

其他回答

而不是添加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/

In my case, everything was working properly then suddenly stopped worked because I think Resharper altered some changes which caused the problem. My project was divided into the data layer, service and presentation layer. I had Entity framework installed and referenced in my data layer but still the error didn't go away. Uninstalling and reinstalling didn't work either. Finally, I solved it by making the data layer the Startup project, making migration, updating the database and changing the Startup project back to my presentation layer.

我得到了同样的错误,而使用实体框架6与SQL Server紧凑4.0。关于EF6实体框架提供者的MSDN的文章很有帮助。在包管理器控制台以nuget包的形式运行相应的提供程序命令可能会解决这个问题,因为nuget包也会自动向配置文件添加注册。我运行PM>安装包实体框架。SqlServerCompact来解决问题。

你不需要在控制台应用程序中安装实体框架,你只需要添加一个对程序集EntityFramework.SqlServer.dll的引用。您可以将此程序集从使用实体框架的类库项目复制到LIB文件夹,并向其添加引用。

总而言之:

类库应用: 安装实体框架 编写数据层代码 app.config文件包含了除了连接字符串之外与实体框架相关的所有配置。 创建一个控制台,web或桌面应用程序: 向第一个项目添加引用。 添加一个对EntityFramework.SqlServer.dll的引用。 app.config /网络。config有连接字符串(记住,配置项的名称必须与DbContext类的名称相同。

我也遇到过类似的问题。我的问题是通过以下方法解决的: