本文介绍了在程序集中找不到上下文类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先使用.NET 4.0,MVC3和EF5。

I'm using .NET 4.0, MVC3, and EF5 with code first.

我的解决方案分为三个项目,其依赖性如下所示:

My solution is split up into three projects, with the dependencies as indicated:

Project.Web-> Project.BLL-> Project.DAL

Project.Web -> Project.BLL -> Project.DAL

Project.DAL层包含我的实体框架数据上下文类和我的所有实体,但是我的启动项目是Project.Web,因此它包含我的Web.config,连接字符串和实际的SQL紧凑数据库。

The Project.DAL layer contains my entity framework data context class and all my entities, but my startup project is Project.Web, so it contains my Web.config, connection strings, and the actual SQL compact database.

我正在尝试启用迁移,以便可以在不擦除现有数据的情况下向EF模型添加新表。但是,当我运行启用迁移时,我得到了

I'm trying to enable migrations so I can add a new table to my EF model without wiping the existing data. However, when I run "Enable-Migrations", I get

No context type was found in the assembly 'Project.Web'.

如果我将启动项目设置为Project.DAL,则错误更改为

If I set the startup project as Project.DAL, the error changes to

Could not load assembly 'Project.Web'. (If you are using Code First Migrations inside Visual Studio this can happen if the startUp project for your solution does not reference the project that contains your migrations. You can either change the startUp project for your solution or use the -StartUpProjectName parameter.)

有人知道为什么会导致此错误,或者我可以如何解决该错误?

Does anyone know why this error is being caused or what I can do to fix it?

推荐答案

我最终在中找到了答案一个>问题。基本上,在Package Manager控制台中,有一个默认项目下拉列表。您需要将此设置为包含EF上下文的项目。

I eventually found the answer in this question. Basically, in the Package Manager Console there's a "Default project" dropdown. You need to set this to the project that contains your EF context.

这篇关于在程序集中找不到上下文类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:25
查看更多