No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误
Posted Stupid_Bire
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误相关的知识,希望对你有一定的参考价值。
最简单的解决方案是将启动项目设置为你要生产Migration的项目。
例如:
我这边将Try.EntityFramework设置为启动项目。并且准备在该项目下生成Migration文件。这里的默认项目同样设置为Try.EntityFramework。就OK了。
2.另一种方案。
查看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 "Try.EntityFramework.TryDbContext" -ProjectName "Try.EntityFramework" -StartUpProjectName "Try.EntityFramework" -ConnectionStringName "Default" -Verbose
依次填好之后,问题解决。
同样的在Add-Migration、Update-Database的时候也需要填写相应的参数。否则会出现同样错误。
例如:
add-migration -Name "InitDb" -ProjectName "Try.EntityFramework" -StartUpProjectName "Try.EntityFramework" -ConnectionStringName "Default" -Verbose
update-database -script -ProjectName "Try.EntityFramework" -StartUpProjectName "Try.EntityFramework" -ConnectionStringName "Default" -Verbose
以上是关于No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误的主要内容,如果未能解决你的问题,请参考以下文章
Flutter No MediaQuery ancestor could be found starting from the context that was passed to MediaQuer
Flutter No MediaQuery ancestor could be found starting from the context that was passed to MediaQuer
Flutter No MediaQuery ancestor could be found starting from the context that was passed to MediaQuer
Rejected because no crossdomain.xml policy file was found