简体   繁体   English

在程序集中找不到上下文类型 - “ApplicationDbContext”类型不是从 DbContext 继承的

[英]No context type was found in the assembly - The type 'ApplicationDbContext' does not inherit from DbContext

When I am trying to update the database It is throwing the following error.当我尝试更新数据库时,它抛出以下错误。 Please note that update-database cmd used to work fine with me before.请注意,update-database cmd 以前对我来说很好用。

No migrations configuration type was found in the assembly 'Tycoon'.在程序集“Tycoon”中找不到迁移配置类型。 (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration). (在 Visual Studio 中,您可以使用包管理器控制台中的 Enable-Migrations 命令添加迁移配置)。

I have tried Enable-Migrations but when I do that I get the following error.我尝试过启用迁移,但是当我这样做时,我收到以下错误。

No context type was found in the assembly 'Tycoon'.在程序集“Tycoon”中找不到上下文类型。

And then I tried this然后我尝试了这个

Enable-Migrations -ProjectName <YOUR_PROJECT_NAME> -ContextTypeName <YOUR_CONTEXT_NAME>

but got the following error.但出现以下错误。

The type 'ApplicationDbContext' does not inherit from DbContext. “ApplicationDbContext”类型不是从 DbContext 继承的。 The DbMigrationsConfiguration.ContextType property must be set to a type that inherits from DbContext DbMigrationsConfiguration.ContextType 属性必须设置为从 DbContext 继承的类型

I am building MVC application with Individual User accounts hence ApplicationDbContext class was created by default which is inherited from IdentityDbContext .我正在使用个人用户帐户构建 MVC 应用程序,因此ApplicationDbContext类是默认创建的,它是从IdentityDbContext继承的。

Please note that I was able to do migrations before but I am not sure why is it throwing errors now.请注意,我之前可以进行迁移,但我不确定为什么现在会抛出错误。

如果您的上下文文件的名称是 ApplicationDbContext,请尝试从基类 DbContext 派生它,如下所示:

public class ApplicationDbContext : DbContext

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 Context 没有从 Entity Framework Core 中的 DbContext 继承 - My Context does not inherit from DbContext in Entity Framework Core ASP.NET 核心 - 无法合并“ApplicationDbContext”类型的 DbContext,因为它没有接受单个参数的公共构造函数 - ASP.NET Core- The DbContext of type 'ApplicationDbContext' cannot be pooled because it does not have a public constructor accepting a single parameter 如何在XAML中将绑定上下文设置为另一个程序集? 找不到类型 - How to set binding context to another assembly in XAML? Type not found EF 5 Enable-Migrations:在程序集中找不到上下文类型 - EF 5 Enable-Migrations : No context type was found in the assembly 在程序集中找不到上下文类型。 ASP.NET MVC4 - No context type found in the assembly. ASP.NET MVC4 ASP.NET MVC:在程序集中找不到上下文类型 - ASP.NET MVC : Context type not found in assembly 通过反射从类型继承 - Inherit from a type by reflection Xamarin XAML:未从外部程序集中找到类型 - Xamarin XAML: Type is not found from external assembly “Type”不包含“Assembly”的定义,并且找不到接受“Type”类型的第一个参数的扩展方法“Assembly” - 'Type' does not contain a definition for 'Assembly' and no extension method 'Assembly' accepting first argument of type 'Type' could be found 无法解析ApplicationDbContext中的类型服务 - Unable to resolve service for type in ApplicationDbContext
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM