Question

DbContext should be defined in the namespace System.Data.Entity inside of the EntityFramework assembly, according to MS docs: http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext(v=vs.103).

I have both referenced in my project (plus System.Data.Entity) but cannot create an instance of DbContext. When I type in DbContext, there is no intellisense. But on the right side of the equation, I do see DbContext in intellisense.

DbContext test = new DbContext();

However, when I build the project, I get this error:

The type or namespace 'DbContext' could not be found.

If I add the fully qualified name, I get this error:

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

I'm using .NET 4.5, VS.NET 2013 Premium and EF 5.

Any ideas what I'm doing wrong?

Was it helpful?

Solution 2

I found the issue. The particular file I was trying to add this to was in a different project. DbContext does work fine in the project where all the references exist.

OTHER TIPS

You said that you don't use nuget? Any specific reason why? Because installing EF via NuGet is your best bet for getting up and running with it quickly and smoothly. To install EF 5, just type this into your Package Manager console (with the project you want it installed into targeted) Install-Package EntityFramework -Version 5.0.0. I'm using .Net 4.5 and VS Premium 2013 as well, and I've verified that using NuGet to install EF 5 or EF 6 works without a problem.

Otherwise, there are numerous other posts here on SO that deal with this issue. Here is one that could probably help you. If you don't use NuGet, the most common issue seems to be missing a reference to either the System.Data.Entity assembly or EntityFramework.dll

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top