[c#] The type or namespace name 'Entity' does not exist in the namespace 'System.Data'

I'm using WS class and it gave me error when I run the application:

The type or namespace name 'Entity' does not exist in the namespace 'System.Data' 

I have a reference to the System.Data; and to System.Data.Entity; But no changes. I keep getting the error. I have also in the web.config the line:

<compilation debug ="true" targetFramework="4.0"/>

This question is related to c# asp.net .net web-services entity-framework-4.1

The answer is


I had the same errors.

I added System.Data.Entity.Repository from Nuget Packages and the errors disappears.

Hope it wil help!


I noticed that in the csproj the framework entity had hintpath like

<HintPath>..\..\..\..\..\..\Users\{myusername}

I had this in the nuget.config file:

 <config>
 <add key="repositoryPath" value="../lib" />
 </config>

a) I removed the above lines, b) uninstalled the framework entity package, c) THEN CLOSED THE solution and reopened it, d) reinstalled the framework.

It fixed my issue.


If you're using a database-first approach:

Before uninstalling / reinstalling Entity Framework, first try simply adding another table / stored procedure to your model (assuming there are any currently unmapped). That fixed the issue for me. Of course if you don't need the resource mapped then just delete it from the model afterwards. But it looks like a force-regeneration of the edmx did the trick.


I found the root cause is when you install the nuget packages through the UI the scripts won't run sometimes. So I'd recommend open Output view while you do that. If you don't see the license agreement window when installing Nuget, there is a better change your IDE isn't doing the job right. So that's why a restart, cleanup and rebuild helps!

PS: That adding anything under System.Data.Entity.* helps because, that triggers the Nuget installer to work properly. But this I found a quite unreliable way.

So just watch the output window, you MUST see something like a successful nuget installation message at the end. Most the time when there an issue, Nuget installer won't even kick off. That's when your restart of IDE is going to help.

When things go well, Nuget package manager and IDE (I used Installer term above) would do the change, compile the solution and keep you happy! But when its not give a little help by restarting IDE and watching that Output window!


I just had the same error with Visual Studio 2013 and EF6. I had to use a NewGet packed Entity Framework and done the job perfectly


tried reinstall - no luck. i had to refresh a table in my model before it would find Entity.


Hi this post is very misleading, if your reading this 2 years on.

With using EF6 and .net 4.5.1 in VS 2013 I have had to reference the following to get this to work

using System.Data.Entity.Core.EntityClient;

a little different to before,

this is more of a FYI for people that come here for help on newer problems than a answer to the original question


I will add my answer to cover all cases:

My solution was unistalling EntityFramework from NuGet Package Manager and then I was prompted to restart Visual Studio because it couldn't "finalize the uninstall".

I restarted Visual Studio and reinstalled EntityFramework then my problem was solved.

Hope this helps someone!


If you are using EF version more than 6.x , then see if you have installed the entity framework nuget package in every project of your solution. You might have installed Ef but not in that particular project which you are working on.


I had just updated my Entity framework to version 6 in my Visual studio 2013 through NugetPackage and add following References:

System.Data.Entity,
System.Data.Entity.Design,
System.Data.Linq

by right clicking on references->Add references in my project. Now delete my previously created Entity model and recreate it again,Built solution. Now It works fine for me.


It's helped me, I uninstalled EF, restarted VS and I added 'using':

using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;

I had to refresh my DBModel. That solved it


Most of the answers here seem to lack awareness of the namespace change that happened between EF 6.2 and 6.3.

I was intentionally upgrading from EF 6.1 to 6.3 to be able to target .NET Standard 2.1. However, I accidentally used .NET Standard 2.0 for the new target in my lib and then got the The type or namespace name 'Entity' does not exist in the namespace 'System.Data'. This GH issue comment gave me the clue I needed to fix. I changed my lib target to .NET Standard 2.1 and the project compiled. No re-installs, uninstalls, or restarts were required.


I installed EntityFramework 6.2 instead of 6.3 and it worked.

Perhaps it is the .NetCoreApp v2.1 or .NETFramework v4.6.1.


I had entity framework 6.1.3, upgraded (well, more downgraded in NuGet) to 6.1.2. Worked.


My solution was simple! I was actually having this error when checked out a repo from a svn server. I took following steps to remove error

  1. Cleaned solution
  2. Went to nuget package manager and uninstalled the entity framework.
  3. Removed DataModel and its .cs components.
  4. Shutdown the VS and opened again.
  5. Installed Entity Framework and Recreated entity model.
  6. Check if there is any files needed "Include in the solution". It worked like a charm

I had to reference System.Data.DataSetExtensions, which seems completely illogical


You need to install Entity framework by right click on your VS solution and click Manage NuGet Package solution and search there Entity framework. After installation the issue will be solved


Right-click on the Solution from the Visual Studio Solution Explorer click the Manage Nuget packages for solution and install the EntityFramework


Make sure you have the EntityFramework Nuget package installed for your project.

From @TonyDing's answer:

Right-click on the Solution from the Visual Studio Solution Explorer click the Manage Nuget packages for solution and install the EntityFramework

Once it is installed, I still had the error, but then did a reinstall per @papergodzilla's comment:

Update-Package -reinstall

and it resolved my issue

Do this in the Package Manager Console (View > Other windows > Package Manager Console).
Now everything is good!


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to web-services

How do I POST XML data to a webservice with Postman? How to send json data in POST request using C# org.springframework.web.client.HttpClientErrorException: 400 Bad Request How to call a REST web service API from JavaScript? The request was rejected because no multipart boundary was found in springboot Generating Request/Response XML from a WSDL How to send a POST request using volley with string body? How to send post request to the below post method using postman rest client How to pass a JSON array as a parameter in URL Postman Chrome: What is the difference between form-data, x-www-form-urlencoded and raw

Examples related to entity-framework-4.1

Entity Framework Join 3 Tables How to include a child object's child object in Entity Framework 5 Ignoring a class property in Entity Framework 4.1 Code First The type or namespace name 'Entity' does not exist in the namespace 'System.Data' Validation failed for one or more entities. See 'EntityValidationErrors' property for more details StringLength vs MaxLength attributes ASP.NET MVC with Entity Framework EF Code First Entity framework code-first null foreign key How do I detach objects in Entity Framework Code First? Entity Framework Code First - two Foreign Keys from same table How Should I Declare Foreign Key Relationships Using Code First Entity Framework (4.1) in MVC3?