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错误

原文地址:https://www.cnblogs.com/FlyStupidBird/p/8944782.html

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

No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误的相关文章

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

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

转自:http://www.cnblogs.com/stevenhqq/archive/2013/04/18/3028350.html 以前做项目的时候,没有采用分类库的形式,所以迁移一致非常顺利,没有出现过任何状况. 这次做项目稍微有点大,必须要分类库才方便开发维护. 在解决方案中启用项目EntityFramework迁移时却发生了异常. 异常说在我的项目中没有找到DBContext类. 这个DBContext类确实没有放在启动项目下面,是另外建立了一个独立的类库来存放. 在启动项目中引用了却

Type &#39;Insus.NET.PictureObject&#39; in Assembly &#39;App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null&#39; is not marked as serializable.

昨晚想实现一个功能,需要把一个对象存储于ViewState中去,但在运行时,出现下面的异常. Type 'Insus.NET.PictureObject' in Assembly 'App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. Description: An unhandled exception occurred during the executi

AddDbContext was called with configuration, but the context type &#39;NewsContext&#39; only declares a parameterless constructor?

问题 An error occurred while starting the application. ArgumentException: AddDbContext was called with configuration, but the context type 'NewsContext' only declares a parameterless constructor. This means that the configuration passed to AddDbContext

Could not load file or assembly ‘xxx’ or one of its dependencies. The located assembly&#39;s manifest definition does not match the assembly reference.

在写aspx web application时,我们有时会遇到这个问题.很多情况都是由于在线安装的Package引起的.系统尝试去找某一个version的dll,但是你却更新了最新的Package,造成不兼容. 解决办法就是检查web.config里如下类似的代码,并手动指定version,并安装或加载你想要version的dll即可. <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <depend

type &#39;simple Class&#39; does not conform to protocol &#39;Example Protocol&#39;错误

在看swift教程中"接口和扩展"这小部分.在编写时提示"type 'simple Class' does not conform to protocol 'Example Protocol'"的错误,原因是simpleClass没有完全实现protocol中定义的方法.检查了下代码,原来是自己把方法名给写错了. mutating 只针对 struct 和 enum  . type 'simple Class' does not conform to protoco

spring错误:&lt;context:property-placeholder&gt;:Could not resolve placeholder XXX in string value XXX

spring同时集成redis和mongodb时遇到多个资源文件加载的问题 这两天平台中集成redis和mongodb遇到一个问题 单独集成redis和单独集成mongodb时都可以正常启动程序,但是当两个同时集成进去时就会报以下问题 Could not resolve placeholder 'mongo.port' in string value "${mongo.port} 百思不得解后,经多方搜集查证,终于找到问题原因. 在spring的xml配置文件中当有多个*.properties文

Found more than one concrete type for given DbContext Type (xxx.xxxx.xxx) define MultiTenancySideAttribute with Tenant

错误提示: Found more than one concrete type for given DbContext Type (Abp.Zero.EntityFramework.AbpZeroCommonDbContext`2[Easyman.Authorization.Roles.Role,Easyman.Users.User]) define MultiTenancySideAttribute with Tenant. Found types: Easyman.EntityFramewo