实体框架中DBContext,DBSet 的引用

时间:2022-09-15 15:41:21

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.

我正在尝试使用最新Entity Framework 4.0的ADO.Net Codefirst功能。作为其中的一部分,我安装了Microsft的Entity Framework CTP 4,并使用Scott的教程首先创建模型。在教程DBContext和DBSet <>中指定。有些人可以告诉我们为了访问这个类而使用的引用是什么。

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

我使用了以下引用,但DBContext和DBSet <>没有任何反应

  • System.Data.Entity
  • System.Data.Entity的
  • System.Data.Entity.Design
  • System.Data.Entity.Design

7 个解决方案

#1


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).

使用CTP5而不是它是更新的版本,在API中有一些变化。您必须添加对安装在CTP目录中的EntityFramework.dll的引用 - 默认为:c:\ Program Files \ Microsoft ADO.NET实体框架功能CTP5 \ Binaries \ EntityFramework.dll适用于32位系统。在64位系统上,它将被放置在Program Files(x86)中。

#2


26  

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

如果有,可以使用库包管理器(它随MVC 3.0自动安装)。

From within your project in Visual Studio 2010, go to

在Visual Studio 2010中的项目中,转到

Tools > Library Package Manager > Package Manager Console

From within your project in Visual Studio 2013, go to

在Visual Studio 2013中的项目中,转到

Tools > NuGet Package Manager > Package Manager Console

In the console, after the PM> prompt, type

在控制台中,在PM>提示符后键入

install-package entityframework

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

这将安装包并将EntityFramework引用添加到项目中。

#3


4  

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

使用“DbContext”vs“DBContext”,以及“DbSet”vs“DBSet”。区分大小写是个问题。

#4


2  

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

要将EF添加到项目,请使用程序包管理器控制台并发出命令:

Install-Package EntityFramework

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

您不应该直接链接到DLL的安装位置,如另一个答案中所述。

#5


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.

上面使用的DbContext和DbSet类是作为EF4 Code-First库的一部分提供的。您需要添加对System.Data.Entity.CTP程序集的引用,该程序集安装在\ Program Files \ Microsoft ADO.NET实体框架功能CTP4 \ Binaries目录中以引用这些类。您还需要在“NerdDinners”类文件的顶部添加“using System.Data.Entity”命名空间语句。

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

但是我确实认为新的CTP5包含了对codefirst的一些更改,所以我建议先看看那个。

#6


1  

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

我正在关注MvcMusicStore教程(使用Mvc 4而不是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).

我在第4部分发现我遇到了这个问题(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:

当我使用System.Data.Entity;添加以下引用时,我收到以下错误:

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

命名空间'system.data'中不存在类型或命名空间名称'entity'

@Fecklmore's solution worked for me.

@ Fecklmore的解决方案对我有用。

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

转到工具>库包管理器>包管理器控制台,打开包管理器控制台。

Then type in the following: Install-Package EntityFramework

然后键入以下内容:Install-Package EntityFramework

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

这将在您的项目中安装EntityFramework(即EF),并将消除上述错误。

#7


0  

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

如果您使用的是.NET 3.5,则将目标框架更改为.NET 4.0

#1


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).

使用CTP5而不是它是更新的版本,在API中有一些变化。您必须添加对安装在CTP目录中的EntityFramework.dll的引用 - 默认为:c:\ Program Files \ Microsoft ADO.NET实体框架功能CTP5 \ Binaries \ EntityFramework.dll适用于32位系统。在64位系统上,它将被放置在Program Files(x86)中。

#2


26  

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

如果有,可以使用库包管理器(它随MVC 3.0自动安装)。

From within your project in Visual Studio 2010, go to

在Visual Studio 2010中的项目中,转到

Tools > Library Package Manager > Package Manager Console

From within your project in Visual Studio 2013, go to

在Visual Studio 2013中的项目中,转到

Tools > NuGet Package Manager > Package Manager Console

In the console, after the PM> prompt, type

在控制台中,在PM>提示符后键入

install-package entityframework

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

这将安装包并将EntityFramework引用添加到项目中。

#3


4  

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

使用“DbContext”vs“DBContext”,以及“DbSet”vs“DBSet”。区分大小写是个问题。

#4


2  

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

要将EF添加到项目,请使用程序包管理器控制台并发出命令:

Install-Package EntityFramework

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

您不应该直接链接到DLL的安装位置,如另一个答案中所述。

#5


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.

上面使用的DbContext和DbSet类是作为EF4 Code-First库的一部分提供的。您需要添加对System.Data.Entity.CTP程序集的引用,该程序集安装在\ Program Files \ Microsoft ADO.NET实体框架功能CTP4 \ Binaries目录中以引用这些类。您还需要在“NerdDinners”类文件的顶部添加“using System.Data.Entity”命名空间语句。

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

但是我确实认为新的CTP5包含了对codefirst的一些更改,所以我建议先看看那个。

#6


1  

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

我正在关注MvcMusicStore教程(使用Mvc 4而不是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).

我在第4部分发现我遇到了这个问题(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:

当我使用System.Data.Entity;添加以下引用时,我收到以下错误:

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

命名空间'system.data'中不存在类型或命名空间名称'entity'

@Fecklmore's solution worked for me.

@ Fecklmore的解决方案对我有用。

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

转到工具>库包管理器>包管理器控制台,打开包管理器控制台。

Then type in the following: Install-Package EntityFramework

然后键入以下内容:Install-Package EntityFramework

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

这将在您的项目中安装EntityFramework(即EF),并将消除上述错误。

#7


0  

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

如果您使用的是.NET 3.5,则将目标框架更改为.NET 4.0