No Entity Framework provider found for the ADO.NET

2019-01-01 09:35发布

After downloading the EF6 by nuget and try to run my project, it returns the following error:

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

enter image description here

30条回答
柔情千种
2楼-- · 2019-01-01 10:26

I had one console application and class library. In class library I created Entity Data Model (right click to Class Library > Add > New Item > Data > ADO.NET Entity Data Model 6.0) and put reference inside console application. So, you have console application which has reference to class library and inside class library you have EF model. I had the same error when I tried to get some records from the table.

I resolved this issue by following these steps:

  1. Right click to solution and choose option 'Manage NuGet Packages for Solution' and NuGet package manager window will show up.
  2. 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
  3. 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)

That's all I had to do and everything worked perfect.

I hope it helped.

查看更多
人间绝色
3楼-- · 2019-01-01 10:26

Note: I had this problem while Generating Database Sql from Model. It had created all the tables fine but wouldn't export the changes. What you need to notice is that this error is generated when you try to export the sql using the DDL Generation Template as SSDLtoSQL10. It is expecting MySQL connection here so make sure you select from the drop down DDL Generation Template SSDLtoMySQL on the Model properties. Spent a whole day on this !

查看更多
初与友歌
4楼-- · 2019-01-01 10:27

Ran into this problem today when working with a set of web services, each in different projects, and a separate project containing integration tests for some of those services.

I've been using this setup for some time with EF5, without needing to include references to EF from the Integration Test Project.

Now, after upgrading to EF6, it seems I need to include a reference to EF6 in the integration test project too, even though it is not used there (pretty much as pointed out above by user3004275).

Indications you're facing the same problem:

  • Calls directly to EF (connecting to a DB, getting data, etc) work fine, as long as they are initiated from a project that has references to EF6.
  • Calls to the service via a published service interface work fine; i.e. there are no missing references "internally" in the service.
  • Calls directly to public methods in the service project, from a project outside the service, will cause this error, even though EF is not used in that project itself; only internally in the called project

The third point is what threw me off for a while, and I'm still not sure why this is required. Adding a ref to EF6 in my Integration Test project solved it in any case...

查看更多
其实,你不懂
5楼-- · 2019-01-01 10:27

I also had a similar problem.My problem was solved by doing the following:

enter image description here

enter image description here

查看更多
宁负流年不负卿
6楼-- · 2019-01-01 10:27

I had the same issue, just copied the App Config file from the project that contained the DBContext to my test project

查看更多
永恒的永恒
7楼-- · 2019-01-01 10:27

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.

查看更多
登录 后发表回答