Entity Framework - The migrations configuration type was not be found in the assembly(实体框架 - 在程序集中找不到迁移配置类型)
问题描述
我在一个 C# 项目中有多个 DbContext,我正在尝试启用迁移.当我指定完整的命令时,即:
I have multiple DbContexts in a C# project and I'm trying to enable migrations. When I specify the full command, i.e.:
Enable-Migrations -ContextTypeName Models.Account.AccountDetailDbContext
使用配置类创建了一个迁移文件夹,但随后我收到一条消息:
A migrations folder is created, with the configuration class, but I then get a message:
检查上下文是否针对现有数据库...
Checking if the context targets an existing database...
然后
在程序集Portal.WebUI"中找不到迁移配置类型Portal.WebUI.Migrations.Configuration".
The migrations configuration type 'Portal.WebUI.Migrations.Configuration' was not be found in the assembly 'Portal.WebUI'.
即使它刚刚创建了文件,也找不到它.
Even though it has just created the file, it can't find it.
我在包管理器控制台中选择了正确的项目
I have the correct project selected in the Package Manager Console
我已尝试使用 -verbose 的命令,但它没有提供额外信息
I have tried the command using -verbose, but it gives no additional information
如果我将 dbcontexts 和类复制到一个新项目中,那么一切正常,所以它一定是这个现有项目中的某些东西导致迁移失败,但我不知道它是什么.
If I copy the dbcontexts and classes into a new project then it all works, so it must be something in this existing project that is making the migration fail, but I can't tell what it is.
推荐答案
我通过在Add-Migration前添加EntityFrameworkCore解决了这个问题,即最终语句为:
I solved this by adding EntityFrameworkCore before Add-Migration, i.e. the final statement was:
EntityFrameworkCoreAdd-Migration
在为您的新迁移命名之后.
After give a name for your new migration.
这篇关于实体框架 - 在程序集中找不到迁移配置类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:实体框架 - 在程序集中找不到迁移配置类型
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
