在通过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。
当前回答
我得到了同样的错误,而使用实体框架6与SQL Server紧凑4.0。关于EF6实体框架提供者的MSDN的文章很有帮助。在包管理器控制台以nuget包的形式运行相应的提供程序命令可能会解决这个问题,因为nuget包也会自动向配置文件添加注册。我运行PM>安装包实体框架。SqlServerCompact来解决问题。
其他回答
添加这个函数
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;
}
}
}
.
我有一个控制台应用程序和类库。在类库中,我创建了实体数据模型(右键单击类库>添加>新项目>数据> ADO。NET实体数据模型6.0),并在控制台应用程序中放置引用。因此,你有控制台应用程序,它引用类库,在类库中,你有EF模型。当我试图从表中获取一些记录时,我遇到了同样的错误。
我通过以下步骤解决了这个问题:
Right click to solution and choose option 'Manage NuGet Packages for Solution' and NuGet package manager window will show up. Go to 'Manage' option under 'Installed packages' TIP: Entity Framework is added to Class Library, so you will have EntityFramework under 'Installed packages' and you'll see 'Manage'option Click on 'Manage' option and check to install package to project which has reference to class library which holds EF model (in my case I set check box to install package to console app which had reference to class library which had EF model inside)
这就是我所要做的一切,一切都很完美。
我希望这对你有所帮助。
我刚刚遇到了同样的问题,它看起来像EntityFramework,虽然从NuGet包管理器安装没有正确安装在项目中。
我设法通过在包管理器控制台运行以下命令来修复它:
PM> Install-Package EntityFramework
你应该强制一个对EntityFramework.SqlServer.dll程序集的静态引用,但是你可以用一种更漂亮的方式来做到这一点,而不是放置一个虚拟代码:
If you already have a DbConfiguration class: public class MyConfiguration : DbConfiguration { public MyConfiguration() { this.SetProviderServices(System.Data.Entity.SqlServer.SqlProviderServices.ProviderInvariantName, System.Data.Entity.SqlServer.SqlProviderServices.Instance); } } If you don't have a DbConfiguration class you must put the following code at app startup (before EF is used): static MyContext() { DbConfiguration.Loaded += (sender, e) => e.ReplaceService<DbProviderServices>((s, k) => System.Data.Entity.SqlServer.SqlProviderServices.Instance); }
另外,确保你的启动项目是包含dbcontext(或相关的app.config)的项目。我的是试图启动一个网站项目,没有所有必要的配置设置。