.net 类型“System.Data.Entity.DbContext”是在未引用的程序集中定义的。您必须添加对程序集“EntityFramework 2”的引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19064449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:28:47  来源:igfitidea点击:

The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework 2

.netentity-framework

提问by Tania Marinova

I've got one solution - the one project is class library with .edmx data model The other is asp.net web forms project.

我有一个解决方案 - 一个项目是带有 .edmx 数据模型的类库另一个是 asp.net web 表单项目。

when i start the solution I get the following exception:

当我开始解决方案时,出现以下异常:

The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

类型“System.Data.Entity.DbContext”是在未引用的程序集中定义的。您必须添加对程序集“EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。

and when I see the references in my asp.net project I see the reference to my class and I can't see reference to entity framework. But the problem is that entity framework is installed both in my class library and web project

当我在我的 asp.net 项目中看到引用时,我看到了对我的类的引用,而我看不到对实体框架的引用。但是问题是我的类库和web项目中都安装了实体框架

回答by Ramesh Rajendran

I think your EntityFrameworkversion was confused

我觉得你的EntityFramework版本很混乱

Please download the correct version by using the NuGetpackage installer.

请使用NuGet软件包安装程序下载正确的版本。

See this discussion for getting started: The type or namespace name 'DbContext' could not be found

有关入门,请参阅此讨论:找不到类型或命名空间名称“DbContext”

And look this same problem and Answer : is Here

看看同样的问题和答案:在这里

回答by Mazhar Khan

I found this solution suitable for me.

我发现这个解决方案适合我。

Adding Entity Framework DLL Reference:-

添加实体框架 DLL 参考:-

  1. Go to c:\Program Files (x86)\Microsoft ASP.NET\ASP.NETMVC 4\Packages\EntityFramework 5.0.0-rc\lib\net45

  2. Add Entity framework DLL

  1. 转到 c:\Program Files (x86)\Microsoft ASP.NET\ASP.NETMVC 4\Packages\EntityFramework 5.0.0-rc\lib\net45

  2. 添加实体框架 DLL

回答by Thilina H

I suggest you to check:

我建议你检查:

Allow NuGet to download missing packages during buildticked please refer this link

Allow NuGet to download missing packages during build打勾请参考这个链接

回答by Harry

If someone has more than one project, you need to install it to the projects that require it. Also what helped me was changing the default project and then installing via package manager console and that resolved it.

如果某人有多个项目,则需要将其安装到需要它的项目中。另外帮助我的是更改默认项目,然后通过包管理器控制台安装并解决了它。

回答by user1336745

I had the same problem and I finally solved it. what you should do is to uninstall every instance of entity framework on your pc. If you have installed it using the setup file you have to remove it from add/remove programs and if you have installed it using the nugget packages, you have to uninstall it from there.

我遇到了同样的问题,我终于解决了。你应该做的是卸载你电脑上的每个实体框架实例。如果您使用安装文件安装它,您必须从添加/删除程序中删除它,如果您使用 nugget 软件包安装它,您必须从那里卸载它。

Then you install in again using the nugget packages and restart your visual studio. This solved my problem.

然后使用 nugget 包再次安装并重新启动 Visual Studio。这解决了我的问题。

回答by Manoj Kargeti

Do this, it will solve the issue as it seems you have not installed Entity Framework properly or it is not working properly, Go to TOOLS > Library Package Manager > Package Manager Console in VS2012 and typed install-package EntityFramework

这样做,它将解决问题,因为您似乎没有正确安装实体框架或它无法正常工作,在 VS2012 中转到 TOOLS > Library Package Manager > Package Manager Console 并键入 install-package EntityFramework

回答by Bruno

I ran into this problem when I pulled a project from SVN to a new computer. Installing Entity Framework via NuGet solved the problem. I installed the most current version which is now 6.1.1

当我将一个项目从 SVN 拉到一台新计算机时,我遇到了这个问题。通过 NuGet 安装实体框架解决了这个问题。我安装了最新版本,现在是 6.1.1

回答by Graham Laight

I already had the correct version of the entity framework DLL, and none of the other answers here worked for me: I had to select the EntityFramework reference in the project, then in the properties, set "Specific Version" to true.

我已经有了实体框架 DLL 的正确版本,这里的其他答案都不适合我:我必须在项目中选择 EntityFramework 引用,然后在属性中,将“特定版本”设置为 true。

回答by Marc Johnston

The error message is telling you that the class library with .edmx data model has the Entity Framework 5 loaded ... (obviously because there are no error messages in the .edmx) ... and your web project is referencing the class library ... so it has access to everything in the class library ... but it cannot handle the data types in the class library because your web project needs a reference to the Entity Framework 5. You will also notice that your intellisense doesn't work for the objects in your class library either.

错误消息告诉您具有 .edmx 数据模型的类库加载了 Entity Framework 5 ...(显然是因为 .edmx 中没有错误消息)...并且您的 Web 项目正在引用类库。 .. 所以它可以访问类库中的所有内容......但它无法处理类库中的数据类型,因为您的 Web 项目需要对实体框架 5 的引用。您还会注意到您的智能感知不起作用对于您的类库中的对象。

Simply add a reference in your web project to the entity framework 5 ... and your all set.

只需在您的 web 项目中添加一个引用到实体框架 5 ... 和您的所有设置。

回答by Kumod Singh

Add the correct reference in *.csproj file. in my cas i have added below in *.csproj file and problem solved.

在 *.csproj 文件中添加正确的引用。在我的 cas 中,我在 *.csproj 文件中添加了下面的内容并解决了问题。

 <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
      <Private>True</Private>
    </Reference>