在通过nuget下载EF6并尝试运行我的项目后,它返回以下错误:
没有为ADO找到实体框架提供程序。NET提供程序,使用不变名称'System.Data.SqlClient'。确保提供者在应用程序配置文件的“entityFramework”部分中注册。更多信息请参见http://go.microsoft.com/fwlink/?LinkId=260882。
在通过nuget下载EF6并尝试运行我的项目后,它返回以下错误:
没有为ADO找到实体框架提供程序。NET提供程序,使用不变名称'System.Data.SqlClient'。确保提供者在应用程序配置文件的“entityFramework”部分中注册。更多信息请参见http://go.microsoft.com/fwlink/?LinkId=260882。
当前回答
添加这个函数
private void FixEfProviderServicesProblem()
到库类中的数据库上下文类,丢失的DLL EntityFramework.SqlServer.dll将被复制到正确的位置。
namespace a.b.c
{
using System.Data.Entity;
public partial class WorkflowDBContext : DbContext
{
public WorkflowDBContext()
: base("name=WorkflowDBConnStr")
{
}
public virtual DbSet<WorkflowDefinition> WorkflowDefinitions { get; set; }
public virtual DbSet<WorkflowInstance> WorkflowInstances { get; set; }
public virtual DbSet<EngineAlert> EngineAlerts { get; set; }
public virtual DbSet<AsyncWaitItem> AsyncWaitItems { get; set; }
public virtual DbSet<TaskItem> TaskItems { get; set; }
public virtual DbSet<TaskItemLink> TaskItemLinks { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
private void FixEfProviderServicesProblem()
{
// The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'
// for the 'System.Data.SqlClient' ADO.NET provider could not be loaded.
// Make sure the provider assembly is available to the running application.
// See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}
}
}
.
其他回答
将以下内容添加到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>
删除bin文件夹帮我解决了这个问题
而不是添加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.SqlServer.dll的引用。您可以将此程序集从使用实体框架的类库项目复制到LIB文件夹,并向其添加引用。
总而言之:
类库应用: 安装实体框架 编写数据层代码 app.config文件包含了除了连接字符串之外与实体框架相关的所有配置。 创建一个控制台,web或桌面应用程序: 向第一个项目添加引用。 添加一个对EntityFramework.SqlServer.dll的引用。 app.config /网络。config有连接字符串(记住,配置项的名称必须与DbContext类的名称相同。
在Azure上从CE db迁移到Sql Server时,我遇到了一个相关的问题。浪费了4个小时来解决这个问题。希望这能挽救一些有类似命运的人。对我来说,我的包中有一个对SqlCE的引用。配置文件。删除它解决了我的整个问题,并允许我使用迁移。太棒了,微软又推出了一项存在不必要的复杂设置和配置问题的技术。