Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type or namespace name 'DbContext' could not be found (EF installed)

I am using VS 2012. I installed with Nuget the EntityFramework (version 6.1.1), and add references to the System.Data and System.Data.Entity, but when I open a new class in the solution and refering to DbContext, it says:

"The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?)"

It's weird beacuse the DbContext is green, like every recognized class, when I press F12 to look into the DbContext class it brings me to the System.Data.Entity.DbContext class as it should be.

public DbContext MyContex { get; set; }

The same happanes with DbSet

public DbSet<TEntity> MySet { get; set; }

What else am I missing?

like image 262
user2254436 Avatar asked Aug 12 '14 16:08

user2254436


5 Answers

I was getting this error after upgrading from Visual Studio 2015 to 2017. I closed VS, deleted my .suo file, restarted VS, rebuilt the solution, and everything works great now.

like image 147
coryvb123 Avatar answered Oct 13 '22 22:10

coryvb123


Install-Package EntityFramework -version 5.0.0

like image 36
CodeArt Avatar answered Oct 14 '22 00:10

CodeArt


Turns out the project was compiled with Target Framework 3.5, when I changed it to 4.5 it worked. Thank you all for you comments.

like image 24
user2254436 Avatar answered Oct 13 '22 23:10

user2254436


using System.Data.Entity;

// this will solve both the DbContext and DbSet errors

like image 33
HulcherApp Avatar answered Oct 13 '22 22:10

HulcherApp


Have you tried referencing EntityFramework.dll instead? Or maybe you can try the fully qualified name " public System.Data.Entity.DbContext MyContex { get; set; } ".

like image 27
Jason Spruce Avatar answered Oct 13 '22 22:10

Jason Spruce