EntityFramework 启用迁移 Enable-Migrations 报异常 "No context type was found in the assembly"

转自:http://www.cnblogs.com/stevenhqq/archive/2013/04/18/3028350.html

以前做项目的时候,没有采用分类库的形式,所以迁移一致非常顺利,没有出现过任何状况。

这次做项目稍微有点大,必须要分类库才方便开发维护。

在解决方案中启用项目EntityFramework迁移时却发生了异常。

异常说在我的项目中没有找到DBContext类。

这个DBContext类确实没有放在启动项目下面,是另外建立了一个独立的类库来存放。

在启动项目中引用了却无法找到。。。

查看get-help Enable-Migrations帮助,发现启用迁移命令带了几个参数。

Enable-Migrations [-ContextTypeName <String>] [-EnableAutomaticMigrations] [-ProjectName <String>] [-StartUpProjectName <String>] [-ConnectionStringName <String>] [-Force] [<CommonParameters>]

ContextTypeName:项目继承自DBContext的类名字。

EnableAutomaticMigrations:开启自动迁移。

ProjectName:存放DBContext类的项目名称。

StartUpProjectName:解决方案中启动项目的名称,作用是调用该项目下的连接字符串。

ConnectionStringName:连接字符串名称

上面五个参数是解决问题必须的,其它的无关紧要。

例如:

Enable-Migrations -ContextTypeName "DBAccessLib.TJSSDBContext" -ProjectName "DBAccessLib" -StartUpProjectName "WebSite" -ConnectionStringName "TJSSDBContext" -Verbose

依次填好之后,问题解决。

同样的在Add-Migration、Update-Database的时候也需要填写相应的参数。否则会出现同样错误。

例如:

Add-Migration -Name "EditCST_DevicePhoto"  -ProjectName "DBAccessLib" -StartUpProjectName "WebSite" -ConnectionStringName "TJSSDBContext" -Verbose

Update-Database -Script -ProjectName "DBAccessLib" -StartUpProjectName "WebSite" -ConnectionStringName "TJSSDBContext"  -Verbose

install-package entityframework -project domain

enable-migrations -ContextTypeName "EFDbContext" -ProjectName "Domain" -

StartUpProjectName "WebUI" -ConnectionStringName "ApplicationServices"

不能建立表 因为这个参数 -script

Add-Migration -Name "a"  -ProjectName "domain" -StartUpProjectName "WebUI" -ConnectionStringName "ApplicationServices"

update-database -script -projectName "Domain" -StartUpProjectName "WebUI" -ConnectionStringName "ApplicationServices"

update-database -projectName "Domain" -StartUpProjectName "WebUI" -ConnectionStringName "ApplicationServices"

原文地址:https://www.cnblogs.com/0819lsl/p/8734430.html

时间: 2024-08-01 07:51:44

EntityFramework 启用迁移 Enable-Migrations 报异常 "No context type was found in the assembly"的相关文章

uwp - 解决在使用EntityFrameworkCore 指令“add-migration xx” 时 报错“No context type was found in the assembly/no migrations configuration type was found in the assembly”

报错截图如下: 网上说的办法试过后不行,然后我卸载所有nuget包从头一步步来,终于找到了问题,在到"Add-Migration"这一步,别急执行指令,先重启一下VS,然后再执行指令就可以了,重启前可以重新生成一下项目. 也就是说在创建完数据模型.配置文件app.config等一些列步骤后先重启VS.

EntityFramework codefirst Enable-Migrations No context type was found in the assembly &ldquo;MyApp.Web&rdquo; error

Enable-Migrations -Force -ContextTypeName "MyApp.Repository.DataContext" -ProjectName "MyApp.Repository" -Startup "MyApp.Web" -ConnectionStringName "DataContext" -verbose

报异常:AnnotationAwareAspectJAutoProxyCreator is only available on Java 1.5 and higher

项目启动时候报异常 1,异常信息 信息: Initializing Spring root WebApplicationContext2017-09-07 17:20:44 [org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189)]-[INFO] Root WebApplicationContext: initialization started2017-09-

azure云迁移后expdp报错ORA-01110: data file 201: &#39;/home/oradata/powerdes/temp01.dbf&#39;

1,expdp的时候报错: 在idc的oracle服务器上正常导入导出都ok的,但是到了azure云上就出故障了: [[email protected] oracle]$ expdp \'powerdesk/testcrmfile\' directory=DIR_DUMP tables=bis_floor,bis_shop,bis_shop_conn,bis_store,bis_cont dumpfile=zhengyin.qu_bak_$(date +%Y%m%d)_02.dmp Export

集合遍历过程iterator, 添加删除元素报异常

list  set  遍历过程中添加或者删除元素,报异常. 使用iterator 也会报异常 ConcurrentModificationException remove只能用迭代器的remove,而不能用集合的remove方法,iterator的remove会维护索引的一致性 iterator it = list.iterator(); while(it.hasnext(0){ obj = it.next(); it.remove(); } 用java.util.concurrent中的类代替

运行时候报异常could only be replicated to 0 nodes instead of minReplication (=1). There are 2 datanode(s) running and no node(s) are excluded in this operation.

运行时候报异常could only be replicated to 0 nodes instead of minReplication (=1).  There are 2 datanode(s) running and no node(s) are excluded in this operation. 解决方法: 1首先看一下dfs.replication的数目是否超过了datanode的数目,应该要小于或者等于datanode的数目. 2更改mapreduce.map.memory.mb

使用SSH框架查出的实体集合用AJAX形式刷新到页面JOSONArray报异常

所报异常:net.sf.json.JSONException: java.lang.reflect.InvocationTargetException 问题根源:数据库中查出的日期是java.sql.Date类型,在用JSONArray.fromobject()是转换日期格式错误,JSONArray的转换日期默认是java.util.Date形式 解决办法: List<ReservationInfo> list = new ArrayList<ReservationInfo>();

启动tomcat后struts框架报异常严重: Exception starting filter struts2 Unable to load configuration.

启动tomcat后struts框架报异常严重: Exception starting filter struts2 Unable to load configuration. 出现此异常是因为,struts.xml定义的版本和 struts2-core-2.1.6.jar里面的struts-default.xml版本不一致!! struts-default.xml文件里面定义的<!DOCTYPE ...>如下: <!DOCTYPE struts PUBLIC "-//Apach

【Debug 报异常】Debug打断点报错

用DEBUG启动项目,项目中打断点的,然后会报异常 解决方法: 第一步: 项目-->Java编译器-->Classfile Generation 复选框 全部勾选 第二步: 替换当前文件运行的JRE为sun提供的,不能是Eclipse自带的JRE Window--->preferences---->java---->Installed JREs--->非EC的JRE