The type 'System.Data.Entity.DbContext' is

2020-05-19 16:41发布

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

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

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

10条回答
够拽才男人
2楼-- · 2020-05-19 17:20

I think your EntityFramework version was confused

Please download the correct version by using the NuGet package installer.

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

And look this same problem and Answer : is Here

查看更多
够拽才男人
3楼-- · 2020-05-19 17:21

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.

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

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-05-19 17:26

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

查看更多
趁早两清
5楼-- · 2020-05-19 17:31

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.

查看更多
登录 后发表回答