-1

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?

4thSpace
  • 43,672
  • 97
  • 296
  • 475

2 Answers2

3

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

Community
  • 1
  • 1
rwisch45
  • 3,692
  • 2
  • 25
  • 36
  • I had already read that post and it didn't help. I don't need nugget since EF is working fine except for DbContext. – 4thSpace May 05 '14 at 19:20
  • @4thSpace If you get type resolution errors for `DbContext` when you do a build, then EF is not working fine. Would you be able to try to do the NuGet install and see if it works for you? – rwisch45 May 05 '14 at 19:22
  • 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. Let the down votes begin. – 4thSpace May 05 '14 at 19:23
  • @4thSpace Glad you got it figured out, but I don't see any need for down votes. Post your answer and mark it as correct, or edit your question to reflect what you found. Either way, it'll help someone else at some point. – rwisch45 May 05 '14 at 19:28
-1

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.

4thSpace
  • 43,672
  • 97
  • 296
  • 475