在通过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。
当前回答
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.
其他回答
您已经将EF添加到类库项目中。你还需要将它添加到引用它的项目(你的控制台应用程序,网站或任何东西)。
你应该强制一个对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); }
而不是添加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/
YourModel扩张。然后打开YourModel.Context.tt下的YourModel.Context.cs类。
我在使用部分添加了以下一行,错误为我修复了。
使用 SqlProviderServices = System.Data.Entity.SqlServer.SqlProviderServices;
您可能必须在每次自动生成文件时将这一行添加到文件中。
您只是缺少了对EntityFramework.SqlServer.dll的引用。对于使用SQL Server的EntityFramework项目,需要引用的两个文件是EntityFramework. sqlserver .dll和EntityFramework.dll