c# - EF core 在 ASP.net core 多层架构中添加迁移

标签 c# asp.net-core command-line entity-framework-core

我最近开始了具有多层架构的 ASP.net 核心项目,其中 CatalogDbContext 和 StartUp 类在不同的层中:

enter image description here

我想将迁移添加到 DroneStore.Data 层。我在命令提示符下将当前目录更改为 ../DroneStore.Data/并添加命令:

dotnet ef migrations add Initial

出现错误:

Unable to create an object of type 'CatalogDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

当我将当前目录更改为 ../DroneStore.Web/并添加此命令时,出现错误:

Your target project 'DroneStore.Web' doesn't match your migrations assembly 'DroneStore.Data'. Either change your target project or change your migrations assembly

有什么建议吗?

最佳答案

1) 在命令提示符下将当前目录更改为:

cd ../DroneStore.Data/

2) 添加到带有启动项目文件夹路径的命令 -s 选项:

dotnet ef migrations add Initial -s ../DroneStore.Web/

关于c# - EF core 在 ASP.net core 多层架构中添加迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54685859/

相关文章:

c# - 模型 View 演示器 : Why is model static?

c# - 在 .NET 中通过套接字发送数据集

azure - 无法将 "WindowsAzure.Storage"依赖项添加到 .Net Core (ASP.NET 5) 类库

c# - 单独库中 Controller 的动态路由前缀

windows - Window 的命令行 (cmd.exe) 命令的最大长度是多少?

bash - 移动 "n"文件,每个文件在 ubuntu 中使用命令行或 bash 移动到特定文件夹

c# - 很好的异常处理

C# regEx 表达式不匹配换行符

c# - 如何在asp.net core中设置linux nlog文件夹

java - 如何从命令行在 Java Gradle 项目中运行 main 方法?