在程序集中找不到上下文类型

编程入门 行业动态 更新时间:2024-10-20 15:55:53
本文介绍了在程序集中找不到上下文类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我首先使用.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.

更多推荐

在程序集中找不到上下文类型

本文发布于:2023-11-14 09:32:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586849.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   上下文   类型   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!