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

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


当前回答

YourModel扩张。然后打开YourModel.Context.tt下的YourModel.Context.cs类。

我在使用部分添加了以下一行,错误为我修复了。

使用 SqlProviderServices = System.Data.Entity.SqlServer.SqlProviderServices;

您可能必须在每次自动生成文件时将这一行添加到文件中。

其他回答

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

我几乎尝试了以上所有方法,但都没有奏效。

只有当我在默认项目EntityFramework和EntityFramework中设置引用的dll时。SqlServer属性从本地复制到True它开始工作了!

引用实体框架所在项目的启动项目需要在bin文件夹中包含以下两个程序集:

EntityFramework.dll EntityFramework.SqlServer.dll

在启动项目的.config文件的<configSections>中添加<section>将使第一个程序集在该bin目录中可用。你可以从实体框架项目的.config文件中复制:

<configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

要使第二个.dll在bin文件夹中可用,尽管不实际,但可以从实体框架项目的bin文件夹中手动复制。 一个更好的选择是在实体框架项目的Post-Build Events中添加以下几行,这将使该过程自动化:

cd $(ProjectDir)
xcopy /y bin\Debug\EntityFramework.SqlServer.dll ..\{PATH_TO_THE_PROJECT_THAT_NEEDS_THE_DLL}\bin\Debug\

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

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

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

删除bin文件夹帮我解决了这个问题