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?
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.
Install-Package EntityFramework -version 5.0.0
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.
using System.Data.Entity;
// this will solve both the DbContext and DbSet errors
Have you tried referencing EntityFramework.dll instead? Or maybe you can try the fully qualified name " public System.Data.Entity.DbContext MyContex { get; set; } ".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With