如何在VS Code中使项目作为启动项目,以及我应该在.net中应用迁移到哪一层



目前我正在使用。net 6和VS Code。

我的项目图层是:

1)webapi层

它包括

<
  • 控制器/gh>
  • 连接字符串
  • Program.cs
  • .csproj文件

2)数据层

它包括

  • 枚举
  • DbContext
  • 数据层接口和存储库
  • .csproj文件

3)服务层

它包括

  • 服务层接口和存储库
  • .csproj文件

添加引用和依赖项。没有构建错误。

我想做迁移。要做到这一点,迁移必须应用到哪一层?

dotnet ef migrations add "Initial Migration"

当所有文件都在一个项目中使用上述代码时,我已经完成了迁移。

我的UI层(webapi层)是启动项目,对吗?我应该做什么,而不是运行webapi.csproj文件?

dotnet run --project ./webapi.csproj

我有没有错过什么?

迁移在数据层完成(DbContext类存在的层)。Webapi层是Startup项目

在指定项目中进行迁移:

dotnet ef migrations add InitialCreate --project ../Datalayer --startup-project ../WebApiLayer

在指定项目中进行更新:

dotnet ef database update --project ../DataLayer --startup-project ../WebApiLayer

最新更新