References for DBContext, DBSet<> in Entity Framework
Asked Answered
A

7

22

I am trying to use ADO.Net Codefirst feature of latest Entity Framework 4.0. As part of that I have installed Entity Framework CTP 4 from Microsft and using Scott's tutorial to create the model first. Inside the tutorial DBContext and DBSet<> is specified. Could some tell what is the reference to be used in order to access this class.

I have used the following references however nothing happens for DBContext and DBSet<>

  • System.Data.Entity
  • System.Data.Entity.Design
Aerodyne answered 4/2, 2011 at 13:56 Comment(0)
J
14

Use CTP5 instead it is newer version with some changes in API. You have to add reference to EntityFramework.dll which is installed in CTP directory - default is: c:\Program Files\Microsoft ADO.NET Entity Framework Feature CTP5\Binaries\EntityFramework.dll for 32bit system. On 64bit system it will be placed in Program Files (x86).

Jackqueline answered 4/2, 2011 at 14:0 Comment(5)
Could you please tell will it support for 64 bit .Net version?Aerodyne
Not anymore. Now you would just use nuget Install-Module entityframeworkMincemeat
@TeunD: Yes, you can post it as separate answer. This answer was pretty valid for the version OP asked ...Jackqueline
Instead of referencing entityframework.dll manually you can install the EntityFramework package from NugetRanite
Post is old...but now I think the link is broken.Scorpio
V
25

You can use the Library Package Manager if you have it (it installs automatically with MVC 3.0).

From within your project in Visual Studio 2010, go to

Tools > Library Package Manager > Package Manager Console

From within your project in Visual Studio 2013, go to

Tools > NuGet Package Manager > Package Manager Console

In the console, after the PM> prompt, type

install-package entityframework

This will install the package and add the EntityFramework reference to your project.

Vituline answered 3/4, 2011 at 3:36 Comment(2)
Install-Package : Unable to find package 'entityframework'At line:1 char:1 ...any idea why?Intentional
Looking at NuGet-Solution package manager, I can see I have EntityFramework installed (v6.0.2)...but DbContext still could not be found. Any help would be great.Intentional
J
14

Use CTP5 instead it is newer version with some changes in API. You have to add reference to EntityFramework.dll which is installed in CTP directory - default is: c:\Program Files\Microsoft ADO.NET Entity Framework Feature CTP5\Binaries\EntityFramework.dll for 32bit system. On 64bit system it will be placed in Program Files (x86).

Jackqueline answered 4/2, 2011 at 14:0 Comment(5)
Could you please tell will it support for 64 bit .Net version?Aerodyne
Not anymore. Now you would just use nuget Install-Module entityframeworkMincemeat
@TeunD: Yes, you can post it as separate answer. This answer was pretty valid for the version OP asked ...Jackqueline
Instead of referencing entityframework.dll manually you can install the EntityFramework package from NugetRanite
Post is old...but now I think the link is broken.Scorpio
C
4

Use "DbContext" vs "DBContext", and "DbSet" vs "DBSet". The case sensitivity is the issue.

Christan answered 11/2, 2011 at 8:21 Comment(2)
Thomas, I have just speciied the code, not copying and pasting this. I used the correct case in my code as it was copied from original tutorial. However thanks for letting me know that the keywords are in incorrect case. Cheers.Aerodyne
thats it...I did the mistake.Erotomania
A
3

To add EF to your project use the Package Manager Console and issue the command:

Install-Package EntityFramework

You shouldn't link directly to the DLLs' installed location as mentioned in another answer.

Assured answered 26/4, 2013 at 20:52 Comment(0)
H
1

The blogpost mentions the assembly:

The DbContext and DbSet classes used above are provided as part of the EF4 Code-First library. You’ll need to add a reference to the System.Data.Entity.CTP assembly that is installed into the \Program Files\Microsoft ADO.NET Entity Framework Feature CTP4\Binaries directory to reference these classes. You’ll also want to add a “using System.Data.Entity” namespace statement at the top of your “NerdDinners” class file.

However I do believe the new CTP5 includes some changes to codefirst, so I would suggest to take a look at that one instead.

Hope answered 4/2, 2011 at 14:0 Comment(2)
Could you please tell will it support for 64 bit .Net version?Aerodyne
I am unsure if there are 64bit assemblies in the CTP. If not, your project will need to target x86.Hope
T
1

I was following the MvcMusicStore Tutorial (using Mvc 4 instead of Mvc 3).

I found in Part 4 I was having issues with this (http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-4).

When I added the following reference using System.Data.Entity;, I got the following error:

the type or namespace name 'entity' does not exist in the namespace 'system.data'

@Fecklmore's solution worked for me.

Open the Package Manager Console by going to Tools > Library Package Manager > Package Manager Console.

Then type in the following: Install-Package EntityFramework

This will install EntityFramework (i.e. EF) into your project, and will eliminate the error above.

Tengler answered 5/8, 2013 at 2:51 Comment(0)
W
0

if you are using .NET 3.5 then change your target framework to .NET 4.0

Whaling answered 15/6, 2011 at 16:12 Comment(1)
Thanks indeed @Arek Bee, I have used .Net 4.0 however some how reference is not there for Entity due to some reason. Later after installing the CTP5 everything was fineAerodyne

© 2022 - 2024 — McMap. All rights reserved.