599

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

Dirk
  • 10,668
  • 2
  • 35
  • 49
Fernando Vellozo
  • 6,195
  • 2
  • 14
  • 12
  • I use EF5 without the `providers` and `provider` stuff, so consider removing it? – ta.speot.is Aug 27 '13 at 02:27
  • 1
    put a copy of your connection string here – pylover Aug 27 '13 at 05:04
  • The connection string is in the picture(App.confing), by the way is very simple, I call the constructor, `public BaseStorage(): base ("RaptorDB") {}`, BaseStorage() inherits from DbContext in EF5 everything worked perfectly, not already in EF6. – Fernando Vellozo Aug 27 '13 at 11:31
  • 12
    Problem will be solved by installing EF6, the second project(Console), thanks to everyone who helped in any way! – Fernando Vellozo Aug 27 '13 at 23:47
  • 4
    For me, this seemed to be caused by Visual Studio not realizing that the EntityFramework.SqlServer assembly was actually used by the base project. If you do something like [@Carra's answer](http://stackoverflow.com/a/23059931/892536), you don't have to add EF to each project that references your base project - much cleaner. – tehDorf Jan 18 '16 at 17:51

35 Answers35

670

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
Jim Aho
  • 9,932
  • 15
  • 56
  • 87
douglaslps
  • 8,068
  • 2
  • 35
  • 54
  • 37
    PMC wrote that 'EntityFramework 6.0.1' already installed, but added it to my console app (which accutally is NOT using EF), but it did the trick for me as well. I I remove EF from console app references, error returns, i don't get this - my console app is using repository project (which uses EF) Thanks for help! – Prokurors Oct 18 '13 at 15:13
  • For my solution the normal entityframework installation worked for all relevant projects except one. This answer fixed it for the last one too. – tomsv Oct 23 '13 at 14:54
  • 35
    Don't forget to add -ProjectName to the command line if you have several projects in your solution...!!! – Eugenio Miró Nov 15 '13 at 00:51
  • 1
    Using `-Pre` option tell nuget to install prerelease packages. I not recommend using it. I have a similar error but the solution was to just install EntityFramework in the host project. I have installed it in a class library but not in the main project (web/console/or whatever), – Davide Icardi Nov 24 '13 at 15:20
  • The `-Pre` is no longer required (EF6 was released) and was removed. Thanks for the information. – douglaslps Nov 28 '13 at 09:58
  • 13
    Same problem here. I had a project that did not have a reference to EF but the EF dll was in the Debug folder. Running this command against this project added `EntityFramework.SqlServer.dll` to the Debug folder - problem solved. – qujck Dec 10 '13 at 19:28
  • hello, I did it but my problem didn't solve. I can't use the NuGet on Online mode. do you have any solution? is there a way to fix this problem in offline mode of NuGet or any other ways? – Esi Oct 07 '14 at 10:37
  • @Esi, as mentioned below, you could copy this assembly from the project that uses EF to another folder and add a reference to it. – douglaslps Oct 07 '14 at 11:17
  • 6
    In my situation this error did not present itself until I deployed the project onto our test server. Indeed it was EntityFramework.SqlServer.dll that was missing and installing EF through package manager worked. It just added the two relevant references to the project and then added the entityFramework settings to the web.config. I guess the local IIS was able source the assembly locally but the full IIS on the web server couldn't due to permissions? – Atters Jan 20 '15 at 03:54
  • I can't believe I spent 3 hours trying to figure this out. Is there anyway to make a test project automatically install all NuGet packages in the referencing project? – coster128 Sep 12 '15 at 00:00
  • The rule is whichever app is trying to access the data needs to have EF installed. So, if you have a UnitTest project trying to test a controller, or your services layer, the UnitTest project will need EF as well. – Fabio S. Dec 27 '16 at 10:48
  • Which assemblies specifically need to be referenced (for those of us who are having the same problem, but cannot use NuGet)? – O. R. Mapper Oct 02 '18 at 20:37
  • This Solved It for me, turned out being a mismatch between SQL version and EF version – hanzolo Jan 14 '21 at 20:20
  • Thanks a lot! in my case SQLite provider factory can not be found and this solution fixed my issue! I used "Install-Package System.Data.SQLite" – Tahirhan Dec 15 '22 at 06:45
411

You've added EF to a class library project. You also need to add it to the project that references it (your console app, website or whatever).

Clément Picou
  • 4,011
  • 2
  • 15
  • 18
  • 270
    This is an absolutely ridiculous answer. Why on earth would I need to do that? And you know what is even more ridiculous? It works. – Robert Mar 13 '14 at 08:59
  • 19
    See my answer below, you don't need to install EF in your console application. – Francisco Goldenstein Apr 09 '14 at 18:19
  • 8
    You answer is correct. Only add reference EntityFramework.SqlServer.dll to frontend project that use a library with EF, fix the problem. So do not use this EF (only the DLL) – Sith2021 May 01 '14 at 19:24
  • 32
    You do not **have to** add a reference to EF in the console/web app. You just need to ensure `EntityFramework.SqlServer.dll` is being copied to the bin directory. Adding a strong reference might break your architecture (if you built multiple tiers, your top-level executing assembly shouldn't even know about EF). Instead, you could ensure the SQL Server provider is copied. See for example http://stackoverflow.com/a/19130718/870604 – ken2k May 11 '15 at 09:44
  • I was getting the same error but after reading your ans i solved it.Thanks – I Love Stackoverflow Oct 29 '15 at 05:21
  • 4
    I suspect the reason that the EntityFramework.SqlServer.dll isn't detected as a dependency is because the Entity Framework loads it dynamically. How is your project supposed to know to copy over the SQL provider when the only reference to it is in the config file? – Joel McBeth Nov 03 '15 at 14:56
  • 3
    Simply add the line "typeof(System.Data.Entity.SqlServer.SqlProviderServices);" into the console app so as to make a dependency, and all will work as per ken2k's post – Ian Apr 05 '17 at 14:36
  • 2
    Works for me. Typically, the error message bears no relation to the actual problem or solution. – Steve Smith Feb 14 '18 at 16:56
  • If you are using Unit Tests, don't forget to add it to UT project, even when you added your main project and the app config – Leandro Bardelli Apr 10 '23 at 21:32
223

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.
starball
  • 20,030
  • 7
  • 43
  • 238
Francisco Goldenstein
  • 13,299
  • 7
  • 58
  • 74
  • 20
    Correct answer. NO need to install EF. EntityFramework.SqlServer.dll . – Tom Stickel Sep 17 '14 at 00:01
  • 15
    I have to agree. This is completely the correct answer. Reference a dll that is 1/2 mb or pull the EF nuget project which is >5.5 mb. Reduces a little the worth of architecting multi tiers too. Poor show from MS really: I have 4 tiers and my top tier should really have no reason to know anything about EF – 72GM Mar 04 '15 at 12:25
  • 20
    Still ridiculous anyway. e.g. Why does a front end would need a reference to SqlServer? The front end couldn't care less, in my case. But it works. +1 – Mike de Klerk Jan 24 '16 at 19:29
  • 2
    This was helpful. Thanks a lot. – peter_the_oak Apr 09 '17 at 12:53
  • After doing this, I got a bizarre error saying `Cannot create file '.mdf' because it already exists. Change the file path or the file name, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.`. After refreshing the app started working. – Robotronx May 20 '17 at 17:54
  • 2
    Won't this make it hard to update versions of EntityFramework? You'd have to remember to go and update the reference to the DLL – crush Oct 24 '17 at 02:39
  • 1
    You can manage NuGet packages at a solution level so you could update all of them in one shot :) – Francisco Goldenstein Oct 24 '17 at 12:30
  • If you look into your bin/Debug folder after just add EntityFramework.SqlServer.dll reference you'll see the EntityFramework.dll anyway, so, You can directly just install EF using nuget – Oscar Acevedo Jan 16 '18 at 15:30
  • Thank you very much. I'm still not quite sure how it was working without it. Last night I had suspended my work in TFS as usual (with my app working) then I resumed it and ran into this issue. – Bonez024 May 04 '18 at 14:35
  • 1
    Where as I agree it would be an overkill to install the entire EF nuget package, doesn't manually adding this create other headaches, if I check in with git (we don't add dll/exe to git) how are my team members going to get the same reference, likewise we use different paths for storing repositories so a hard coded reference may not work either. Also if I update EF nuget in host package, do I then have to remember to recopy the latest version of the dll to the correct location so there is not dll hell going on? Just a thought... – s1cart3r Sep 13 '19 at 15:00
116

You can also see this message if you forget to include "EntityFramework.SqlServer.dll".

It appears to be a newly added file in EF6. Initially I hadn't included it in my merge module and ran into the problem listed here.

Ravi Ram
  • 24,078
  • 21
  • 82
  • 113
Mike
  • 2,035
  • 1
  • 16
  • 16
  • 7
    I ran into this problem when I previously had a project (a) with a reference to a project (b) which had a reference to EF. After cleaning & deleting project (a) bin folder, then rebuilding, the EF reference came across, but not EF.SqlServer.dll. Copying this in manually worked for me – dan richardson Dec 04 '13 at 15:18
  • 2
    @dan richardson thanks for mentioning to 'delete bin folder'. – Rajshekar Reddy Dec 30 '13 at 08:03
  • I got the error when trying to run a LINQPad script after an EF6 upgrade. Even referencing EntityFramework.SqlServer.dll in LINQPad did not fix it UNTIL I rebuilt my solution in VS2013. The new reference then resolved properly in LINQPad and my script ran! – Christopher Feb 22 '14 at 17:12
  • In my case I was ok at dev enviroment but when I published appears the referenced issue. After compare the list of libraries in dev against the bin folder in the server I noticed the absent of EntityFramework.SqlServer.dll, I just to upload it and refresh the app, and voila it fixed. – Henry Rodriguez May 02 '14 at 17:07
  • This was the issue for me, thanks! See the clean solution by @Anders to avoid issues forgetting to include the DLL in every required project. – SharpC Jan 02 '20 at 16:55
61

Instead of adding EntityFramework.SqlServer to host project you can ensure a static reference to it from your Model/entity project like this

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

This will make the build process include the assembly with the host project.

More info on my blog http://andersmalmgren.com/2014/08/20/implicit-dependencies-and-copy-local-fails-to-copy/

Anders
  • 17,306
  • 10
  • 76
  • 144
  • 5
    I think this is a nice clean solution where we don't have to include references to persistence related DLLs in projects that should be persistence agnostic. – JTech Dec 16 '15 at 23:28
  • 3
    Agreed, and it applies to any library with implicit dependencies not just persistence – Anders Dec 17 '15 at 07:12
  • 1
    To be honest though @Anders, I don't quite understand *why* this works. Are you able to update your blog post, or answer here, to explain why? – JTech Dec 17 '15 at 23:43
  • 3
    When you have an explicit dependency on a type in a assembly it will be copied by the build process. However here you don't have an explicit dependency, and the build process will fail to copy the assembly to the build folder. My code just make sure there exists a explicit reference to any type in said assembly. – Anders Dec 18 '15 at 07:24
  • 1
    Could someone please explain why this works and why it doesn't work without it.!!!! – Seabizkit Mar 17 '16 at 12:27
  • 2
    Without it there is no explicit dependency to the assembly from your code and it will not be copied to output – Anders Mar 17 '16 at 15:18
  • 2
    This is brilliant. – Kris Apr 04 '16 at 08:19
  • Say, how the `var type` can ever turn out to be NULL if this code passes build phase? IMHO the if/throw is a completely unnecessary noise. – quetzalcoatl May 21 '17 at 20:19
  • 1
    This should be the accepted answer!! Nice and clean. – Dávid Molnár Jun 18 '17 at 09:38
  • 1
    @quetzalcoatl It removes warning from compiler, it tells other devs why the code is there. – Anders Jun 30 '17 at 07:17
  • @Anders: I know the cause, but I just mean that this kind of impossible if(x==null) looks weird and can actually start complaining when null-checking in the compiler gets better. `typeof` **never** returns null.. first random shot from one of my pet projects https://pastebin.com/JgcT2XEg - no if, no throw, no warning, perfectly clear to others; feel free to use if you like it. – quetzalcoatl Jun 30 '17 at 08:49
  • I wouldn't say that has less noise, just different approach – Anders Jun 30 '17 at 11:02
  • Doesn't this kind of detract from the whole idea of the abstraction of the database implementation? What if you aren't using Sql Server as your database implementation with EF? Seems like you'd still get the SqlServer DLL in your final project. This seems like a bad idea for a distributed class library. – crush Oct 24 '17 at 02:35
  • Quit the opposite, the dependency is close to the actual code that is dependent of it, instead of the host project marshaling the dependency. edit: But yeah if you have a class library with general implementation you should not use it. Most backends are not – Anders Oct 24 '17 at 11:04
  • This should be the accepted answer! (At least if bound to SqlServer.) – Rick Love Dec 07 '18 at 17:14
  • 1
    Truly this is the absolute correct answer. All database engine events stay in the referenced project from the front end! Excellent!! – Frank Thomas May 18 '20 at 14:12
50

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.

Umar Abbas
  • 4,399
  • 1
  • 18
  • 23
  • 3
    Well this isn't pretty but it fixed the issue I was having in my test project. None of the other solutions worked. – Honorable Chow May 09 '14 at 14:43
  • In my case it was enough to add the Entity Framework also to my test project in "Manage Nuget packets for the solution" – Juha Palomäki Jul 12 '14 at 19:45
  • actualy you need to put into any project (not only test) to be insured that System.Data.Entity.SqlServer will be included into "results lib set" after compilation (note: Unity or other IoC tool could change this rule and you will need to call this code from test project). – Roman Pokrovskij Jan 28 '15 at 09:53
  • This is actually the best solution, because you don't have to spray entity framework references everywhere in your project. – Daniel Lobo Jul 18 '17 at 17:43
  • This pointed me to the right direction. The `EntityFramework.SqlServer` is added to your class library, but if not used, it will not be placed inside the output folder of your application. I fixed the issue by adding an `ExecutionStrategy`, which I still needed to do, so adding a line like `SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());` inside a `DbConfiguration` class fixed the problem. – Jan_V Dec 28 '17 at 11:42
28

Add this function

private void FixEfProviderServicesProblem()

to database context class in the library class and the missing DLL EntityFramework.SqlServer.dll will be copied to the correct places.

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

.

Johannes
  • 3,002
  • 4
  • 33
  • 36
  • sorry trying to revoke it ... as i didn't think it would work... and it does!... it says i cant change my vote, unless the answer is edited, cozs its been too long and has since been locked... – Seabizkit Mar 31 '16 at 08:12
  • This worked for me too. We have a library project that uses EF 6, and a console application that uses the library. We were getting the same exception as the OP. We do not wish to place EntityFramework-specific configuration in the application configuration file, so this method worked for us. Thanks – Rob Oct 24 '16 at 09:31
  • 1
    Where do you call `FixEfProviderServicesProblem` I tried in the constructor, with no luck. – Francis Ducharme Jan 18 '17 at 21:57
  • 1
    I never call it - don't have to. The fact that is is there makes .net think its needed and includes the EntityFramwork as dependency. – Johannes Jan 21 '17 at 15:54
  • Probably from https://stackoverflow.com/a/19130718/1467396 ? But +1, anyway for the clarity in how/where to use it. – David Jan 04 '19 at 20:16
22

None of these worked for me. I did find the solution in another stackoverflow question. I'll add it here for easy reference:

You need to make a reference, so it will be copied in den application path. Because later it will be referenced in runtime. So you don't need to copy any files.

private volatile Type _dependency;

public MyClass()
{
    _dependency = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
}
Community
  • 1
  • 1
Carra
  • 17,808
  • 7
  • 62
  • 75
9

The startup project that references the project where Entity Framework is being used needs the following two assemblies in it's bin folder:

  • EntityFramework.dll
  • EntityFramework.SqlServer.dll

Adding a <section> to the <configSections> of the .config file on the startup project makes the first assembly available in that bin directory. You can copy this from the .config file of your Entity Framework project:

<configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

To make the second .dll available in the bin folder, although not practical, a manual copy from the bin folder of the Entity Framework project can be made. A better alternative is to add to the Post-Build Events of the Entity Framework project the following lines, which will automate the process:

cd $(ProjectDir)
xcopy /y bin\Debug\EntityFramework.SqlServer.dll ..\{PATH_TO_THE_PROJECT_THAT_NEEDS_THE_DLL}\bin\Debug\
Leonel B.
  • 185
  • 3
  • 5
  • 4
    Thanks, I have Entity framework in a data layer so its isolated but it is unfortunate that microsoft wont allow us to truely isolate the data layer and makes us pollute the ux with a database technology. I was hoping i wouldnt have to do that. – Matt Mar 22 '19 at 11:19
8

I got the same error while using Entity Framework 6 with SQL Server Compact 4.0. The article on MSDN for Entity Framework Providers for EF6 was helpful. Running the respective provider commands as nuget packages at Package Manager Console might solve the problem, as also NuGet packages will automatically add registrations to the config file. I ran PM> Install-Package EntityFramework.SqlServerCompact to solve the problem.

Pragmateek
  • 13,174
  • 9
  • 74
  • 108
MaySara
  • 81
  • 1
  • 2
  • 2
    I'm truly amazed nobody voted for this so far! The error message states clearly: the reason for the error is that after the EF upgrade, there's really no provider definition left for the SQL Compact in the application's web.config file! Adding the package you mention fixes the web.config file, and there will be provider defined. – Csaba Toth Jun 08 '14 at 00:32
  • 1
    simply life saver. It should be marked as answer as it clearly provides solution to the problem – ZafarYousafi Jul 08 '14 at 11:17
8

When the error happens in tests projects the prettiest solution is to decorate the test class with:

[DeploymentItem("EntityFramework.SqlServer.dll")]
Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
Alberto Juan
  • 76
  • 2
  • 8
  • It´s pretty indeed, but generates more work and is easier to forget. With the "forced reference" trick, you only need to do it on the project(s) that really need to use EF. – Charles Roberto Canato Feb 23 '16 at 10:57
7

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...

Community
  • 1
  • 1
Kjartan
  • 18,591
  • 15
  • 71
  • 96
5

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>
Taran
  • 2,895
  • 25
  • 22
  • 1
    You also need to register it to `` - `
    `
    – TryingToImprove Jun 28 '17 at 08:02
  • This is what "IInstall-Package EntityFramework" does. This is not really necessary because EntityFramework by default tries to load EntityFramework.SqlServer.dll for the SqlClient invariant name. This method can be used to substitute the provider. – user1295211 Jun 30 '17 at 06:59
4

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.

Ondřej
  • 1,645
  • 1
  • 18
  • 29
4

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

enter image description here

enter image description here

BehrouzMoslem
  • 9,053
  • 3
  • 27
  • 34
4

You are just missing a reference to EntityFramework.SqlServer.dll. For EntityFramework projects using SQL Server, the two files you need to refer are EntityFramework.SqlServer.dll and EntityFramework.dll

user2956314
  • 174
  • 4
4

just Copy EntityFramework.SqlServer.dll into bin folder

yaserjalilian
  • 161
  • 2
  • 2
3

Deleting the BIN-Folder did it for me

David
  • 2,551
  • 3
  • 34
  • 62
3

You should force a static reference to the EntityFramework.SqlServer.dll assembly, but instead of putting a dummy code, you can do this in a more beautiful way:

  1. 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);
        }
    }
    
  2. 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);
    }
    
Rosberg Linhares
  • 3,537
  • 1
  • 32
  • 35
3

it looks like nobody mentioned first checking if System.Data.SqlClient is installed in the system and if a reference is made to it.

i solved my issue by installing System.Data.SqlClient and adding in a new provider in app.Config

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
Tobi Owolawi
  • 550
  • 1
  • 4
  • 14
2

I have just re-installed the Entity Framework using Nuget. And follow the instruction written on the link below : http://robsneuron.blogspot.in/2013/11/entity-framework-upgrade-to-6.html

I think the problem will get solved.

Kuntal Ghosh
  • 3,548
  • 2
  • 17
  • 21
  • An explanation would be nice! Why you have to re-install it and so on – Rizier123 Dec 04 '14 at 08:43
  • 1
    Because for some unknown reason(s) the changes will not going to take effect and so I re-installed the EntityFramework 6.1.1 and after that it takes effect. – Kuntal Ghosh Dec 04 '14 at 08:57
2

Expand YourModel.edmx file and open YourModel.Context.cs class under YourModel.Context.tt.

I added the following line in the using section and the error was fixed for me.

using SqlProviderServices = System.Data.Entity.SqlServer.SqlProviderServices;

You may have to add this line to the file each time the file is auto generated.

user2347528
  • 580
  • 1
  • 8
  • 22
2

I have the same error. It's weird that it only happens whenever I used my dbContext to query to any of my model or get its list like:

var results = _dbContext.MyModel.ToList();

We tried to reinstall the Entity Framework, reference it properly but to no avail.

Luckily, we tried to check the Nuget for ALL solutions, then update everything or make sure everything is the same version because we noticed that the two projects has different EF versions on the Web project. And it works. The error is gone.

Here is the screenshot on how to Manage Nuget for all solutions:

enter image description here

Willy David Jr
  • 8,604
  • 6
  • 46
  • 57
2

Just Install EntityFramework package to your Web/Console Project. That should add the section to your config file.

Vijaya Malla
  • 209
  • 1
  • 2
  • 11
1

Also, make sure you startup project is the project that contains your dbcontext (or relevant app.config). Mine was trying to start up a website project which didnt have all the necessary configuration settings.

1

I tried almost all the above and nothing worked.

Only when I set the referenced DLLs in the Default Project EntityFramework and EntityFramework.SqlServer properties Copy Local to True did it start working!

SharpC
  • 6,974
  • 4
  • 45
  • 40
  • These already exist in the compile time assemblies of EntityFramework (6.4.4). Location is C:\Users\\.nuget\packages\entityframework\6.4.4\lib\netstandard2.1. Can you share a bit more with what you've done to make these "referenced"? – Jamie Jan 02 '22 at 18:49
1

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

Vahid Akbari
  • 189
  • 7
  • 25
1

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.

dkero
  • 121
  • 1
  • 8
1

I have the same issue(in my 3-Tire level project) and I fixed it by adding/installing the EF to my main Project.

msz
  • 311
  • 1
  • 2
  • 16
0

I had a related issue when migrating from a CE db over to Sql Server on Azure. Just wasted 4 hrs trying to solve this. Hopefully this may save someone a similar fate. For me, I had a reference to SqlCE in my packages.config file. Removing it solved my entire issue and allowed me to use migrations. Yay Microsoft for another tech with unnecessarily complex setup and config issues.

user2662643
  • 59
  • 1
  • 4
0

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

0

I had the identical exception thrown. I included

using System.Data; 
using System.Data.Entity;

and everything is back to working again ..

0

As message shows that we need to add provider System.Data.SqlClient that's why we need to install nuget package of EntityFramework that has two dll but if we are developing only console application then we just need to add reference of EntityFramework.SqlServer.dll

Sandeep Shekhawat
  • 685
  • 1
  • 9
  • 19
0

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 !

0

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.

Alf Moh
  • 7,159
  • 5
  • 41
  • 50