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.
这篇关于实体框架 - 在程序集中找不到迁移配置类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:实体框架 - 在程序集中找不到迁移配置类型
基础教程推荐
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
