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

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


当前回答

你应该强制一个对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); }

其他回答

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.

如果你忘记包含"EntityFramework.SqlServer.dll",你也可以看到这个消息。

它似乎是EF6中新添加的文件。最初我没有将它包含在合并模块中,遇到了这里列出的问题。

添加这个函数

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;
        }
    }
}

.

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

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

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

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