Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type or namespace name 'DbContext' could not be found [closed]

People also ask

What namespace is the DbContext class found under?

The by-convention name is the full name (namespace + class name) of the derived context class. See the class remarks for how this is used to create a connection. Constructs a new context instance using the existing connection to connect to a database.

Are you missing a using directive or an assembly reference in MVC?

Open your Project within the Solution Explorer. Right-click the References folder and Choose Add Reference.... Find and select the assembly that cooresponds to your error message or class. Click the Ok button to add it to your Project.


I had the same issue. Turns out, you need the EntityFramework.dll reference (and not System.Data.Entity).

I just pulled it from the MvcMusicStore application which you can download from: http://mvcmusicstore.codeplex.com/

It's also a useful example of how to use entity framework code-first with MVC.


You need to reference the System.Data.Entity assembly in your project, or install the EntityFramework NuGet package, which will setup everything for you.


Just a quick note. It is DbContext, not DBContext. i.e. with a lowercase 'B'. I discovered this because I had the same problem while intelesense was not working until I tried typing the full name space System.Data.Entity... and name and finally it suggested the lowercase 'b' option:-

System.Data.Entity.DbContext


I had the same problem using VS2010. I know this isn't really an answer. I just thought it might help someone. I resolved it by using the fully qualified name for DBContext.

Instead of

public class MachineDbContext : DbContext

I used

public class MachineDbContext : System.Data.Entity.DbContext

and rebuilt the project. Suddenly VS was happy, and I was even able to remove the fully qualified name, and just use DBContext.


I had the same issue... Installing the EF from Package Manager Console worked for me

the command was: Install-Package EntityFramework


If your compiler doesn't recognize

  • System.Data.Entity.Infrastructure
  • DbContext
  • DbSet
  • et alii,

make sure

  1. you have Entity Framework 4.1 installed on your machine;
  2. in your .csproj file, you have the following reference

    <Reference Include="EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
    

    within the element

    <ItemGroup>
      ...
    </ItemGroup>
    

    that houses references to other assemblies.


I had the same problem..I have VS2010 express..

(Note: If you see this problem try checking references to EntityFramework.dll .. May be it is missing.)

The following resolved it for me.

I installed latest MVC 3 Tools Update
then I installed EntityFramework 4.1
or using NUGet ie. from with Visual Studio 2010 Express (Tools->Library Package Manager -> Add library Package reference -> Select Online -> EntityFramework)

Strangely that didnt work..So i had to manually add a reference to "EntityFramework.dll"
try doing a search for the dll ..may be here
"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\"

If you already have it..just add a '.net' reference.

Note: If you use NuGet ,it creates a folder "packages" along side your Solution directory. You will find the "EntityFramework.4.1.10331.0" folder inside it.Within "Libs" folder you will find "EntityFramework.dll" .
Add reference to it using Browse tab and select the above dll.

Snap for the same