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:15

I just got into the same problem and it looks like EntityFramework although installed from NuGet Package Manager was not correctly installed in the project.

I managed to fix it by running the following command on Package Manager Console:

PM> Install-Package EntityFramework
查看更多
若你有天会懂
3楼-- · 2019-01-01 10:19

Add below to your 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>
查看更多
永恒的永恒
4楼-- · 2019-01-01 10:19

everybody I need your Attention that two dll EntityFramework.dll And EntityFramework.SqlServer.dll are DataAccess layer Library And it is not Logical to Use them in view or any other layer.it solves your problem but it is not logical.

logical way is that enitiess attribute remove and replace them with Fluent API.this is real solution

查看更多
忆尘夕之涩
5楼-- · 2019-01-01 10:20

When you install Entity Framework 6 through Nuget. EntityFramework.SqlServer sometime miss for another executable. Simply add the Nuget package to that project.

Sometimes above does not work for Test Project

To solve this issue in Test Project just place this Method inside Test Project:

public void FixEfProviderServicesProblem()
{
    var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}

This method is never been called, but as my observations, the compiler will remove all "unnecessary" assemblies and without using the EntityFramework.SqlServer stuff the test fails.

查看更多
十年一品温如言
6楼-- · 2019-01-01 10:21

You don't need to install Entity Framework in your Console application, you just need to add a reference to the assembly EntityFramework.SqlServer.dll. You can copy this assembly from the Class Library project that uses Entity Framework to a LIB folder and add a reference to it.

In summary:

  • Class Library application:
    • Install Entity Framework
    • Write your data layer code
    • app.config file has all the configuration related to Entity Framework except for the connection string.
  • Create a Console, web or desktop application:
    • Add a reference to the first project.
    • Add a reference to EntityFramework.SqlServer.dll.
    • app.config/web.config has the connection string (remember that the name of the configuration entry has to be the same as the name of the DbContext class.

I hope it helps.

查看更多
回忆,回不去的记忆
7楼-- · 2019-01-01 10:21

I just run into this problem today. I have data repository class library with EF63 NuGet package and console application for testing, which have reference only to class library project. I created very simple post-build command, which copies EntityFramework.SqlServer.dll from class library's Bin\Debug folder to console application's Bin\Debug folder and problem solved. Do not forget to add entityFramework section to console application's .config file.

查看更多
登录 后发表回答