No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'
Asked Answered
H

35

600

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

Hammad answered 27/8, 2013 at 1:58 Comment(5)
I use EF5 without the providers and provider stuff, so consider removing it?Plug
put a copy of your connection string hereUzia
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.Hammad
Problem will be solved by installing EF6, the second project(Console), thanks to everyone who helped in any way!Hammad
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, you don't have to add EF to each project that references your base project - much cleaner.Merras
C
674

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
Circumlunar answered 5/9, 2013 at 17:28 Comment(14)
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!Chloropicrin
For my solution the normal entityframework installation worked for all relevant projects except one. This answer fixed it for the last one too.Involucrum
Don't forget to add -ProjectName <ProjectName> to the command line if you have several projects in your solution...!!!Calvinism
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),Parliamentarianism
The -Pre is no longer required (EF6 was released) and was removed. Thanks for the information.Circumlunar
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.Untuck
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?Vaules
@Esi, as mentioned below, you could copy this assembly from the project that uses EF to another folder and add a reference to it.Circumlunar
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?Thigpen
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?Loosestrife
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.Trisect
Which assemblies specifically need to be referenced (for those of us who are having the same problem, but cannot use NuGet)?Tabaret
This Solved It for me, turned out being a mismatch between SQL version and EF versionRema
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"Ancheta
P
413

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

Pagas answered 18/11, 2013 at 10:24 Comment(9)
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.Brookner
See my answer below, you don't need to install EF in your console application.Riarial
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)Liesa
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 https://mcmap.net/q/65608/-entity-framework-provider-type-could-not-be-loadedHaft
I was getting the same error but after reading your ans i solved it.ThanksMencher
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?Nautical
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 postMacklin
Works for me. Typically, the error message bears no relation to the actual problem or solution.Kelson
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 configXylophone
R
226

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.
Riarial answered 9/4, 2014 at 18:18 Comment(9)
Correct answer. NO need to install EF. EntityFramework.SqlServer.dll .Jackscrew
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 EFArchetype
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. +1Junna
After doing this, I got a bizarre error saying Cannot create file '<sql_express_db_path>.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.Hertzog
Won't this make it hard to update versions of EntityFramework? You'd have to remember to go and update the reference to the DLLSpindry
You can manage NuGet packages at a solution level so you could update all of them in one shot :)Riarial
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 nugetTelephony
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.Cordierite
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...Mckown
T
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.

Terni answered 4/11, 2013 at 21:4 Comment(5)
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 meGrapher
@dan richardson thanks for mentioning to 'delete bin folder'.Minnieminnnie
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!Tutor
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.Aiello
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.Hallvard
G
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/

Gremlin answered 20/4, 2015 at 9:17 Comment(16)
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.Trouble
Agreed, and it applies to any library with implicit dependencies not just persistenceGremlin
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?Trouble
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.Gremlin
Could someone please explain why this works and why it doesn't work without it.!!!!Roughen
Without it there is no explicit dependency to the assembly from your code and it will not be copied to outputGremlin
This is brilliant.Guggle
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.Righthand
This should be the accepted answer!! Nice and clean.Hautrhin
@Righthand It removes warning from compiler, it tells other devs why the code is there.Gremlin
@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 pastebin.com/JgcT2XEg - no if, no throw, no warning, perfectly clear to others; feel free to use if you like it.Righthand
I wouldn't say that has less noise, just different approachGremlin
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.Spindry
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 notGremlin
This should be the accepted answer! (At least if bound to SqlServer.)Ticonderoga
Truly this is the absolute correct answer. All database engine events stay in the referenced project from the front end! Excellent!!Jeanniejeannine
C
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.

Croesus answered 18/4, 2014 at 20:16 Comment(5)
Well this isn't pretty but it fixed the issue I was having in my test project. None of the other solutions worked.Carabiniere
In my case it was enough to add the Entity Framework also to my test project in "Manage Nuget packets for the solution"Point
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).Cotoneaster
This is actually the best solution, because you don't have to spray entity framework references everywhere in your project.Jourdan
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.Triangulate
P
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;
        }
    }
}

.

Pas answered 16/3, 2016 at 13:16 Comment(5)
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...Roughen
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. ThanksKozak
Where do you call FixEfProviderServicesProblem I tried in the constructor, with no luck.Observable
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.Pas
Probably from https://mcmap.net/q/65608/-entity-framework-provider-type-could-not-be-loaded ? But +1, anyway for the clarity in how/where to use it.Flavio
E
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);
}
Erinnerinna answered 14/4, 2014 at 12:20 Comment(1)
This! No need to add a reference to other projects that might reference this assembly.Merras
K
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\
Kassa answered 16/6, 2018 at 14:12 Comment(1)
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.Heraldic
L
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.

Lawerencelawes answered 29/4, 2014 at 5:39 Comment(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.Doone
simply life saver. It should be marked as answer as it clearly provides solution to the problemLockett
Q
8

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

[DeploymentItem("EntityFramework.SqlServer.dll")]
Quail answered 30/9, 2015 at 9:27 Comment(1)
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.Humanitarianism
L
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...

Languor answered 12/2, 2014 at 16:54 Comment(0)
H
6

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>
Handbag answered 1/12, 2015 at 18:33 Comment(2)
You also need to register it to <configSections> - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />Gschu
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.Cowbird
R
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.

Reseta answered 26/3, 2015 at 12:40 Comment(0)
F
4

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

enter image description here

enter image description here

Fossilize answered 12/10, 2017 at 15:7 Comment(0)
E
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

Extrusion answered 17/8, 2018 at 8:1 Comment(0)
D
4

just Copy EntityFramework.SqlServer.dll into bin folder

Dealing answered 3/5, 2020 at 1:46 Comment(0)
F
3

Deleting the BIN-Folder did it for me

Flavio answered 31/1, 2014 at 19:18 Comment(0)
R
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);
    }
    
Respite answered 1/3, 2017 at 20:51 Comment(0)
P
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"/>
Parkin answered 30/8, 2018 at 22:30 Comment(0)
E
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.

Euterpe answered 4/12, 2014 at 8:17 Comment(2)
An explanation would be nice! Why you have to re-install it and so onMetamorphic
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.Euterpe
T
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.

Terrazas answered 1/6, 2017 at 14:38 Comment(0)
F
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

Fridafriday answered 7/3, 2018 at 13:28 Comment(0)
H
2

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

Historiated answered 31/5, 2018 at 14:21 Comment(0)
V
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.

Vespertine answered 28/3, 2014 at 21:40 Comment(0)
H
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!

Hallvard answered 27/5, 2016 at 12:21 Comment(1)
These already exist in the compile time assemblies of EntityFramework (6.4.4). Location is C:\Users\<profilename>\.nuget\packages\entityframework\6.4.4\lib\netstandard2.1. Can you share a bit more with what you've done to make these "referenced"?Helyn
M
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

Mordancy answered 10/7, 2016 at 15:15 Comment(0)
A
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.

Alyshaalysia answered 4/11, 2016 at 18:29 Comment(0)
S
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.

Shackle answered 18/2, 2021 at 17:31 Comment(1)
Anders solution is better IMO - you don't need the EF package in the UI.Implore
C
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.

Counterweight answered 25/11, 2013 at 23:37 Comment(0)
A
0

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

Anthropophagi answered 8/1, 2015 at 14:2 Comment(0)
S
0

I had the identical exception thrown. I included

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

and everything is back to working again ..

Suckerfish answered 21/3, 2015 at 13:37 Comment(0)
S
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

Stockwell answered 28/8, 2015 at 5:32 Comment(0)
L
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 !

Landis answered 23/8, 2016 at 13:46 Comment(0)
B
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.

Bellbird answered 23/5, 2017 at 4:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.