微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 IDesignTimeDbContextFactory?

如何解决如何使用 IDesignTimeDbContextFactory?

我正在尝试使用 dotnet cli ef 工具在具有两个 netstandard2.0 项目的存储库上进行迁移。 一个用于域,另一个用于基础设施,来自 eshop-on-container 的存储库的 Ordering Service

我看到基础设施项目已经在 OrderingContext.cs 中实现了 IDesignTimeDbContextFactory

如果我错了,请纠正我,但据我所知,这意味着即使没有将启动项目传递给 dotnet cli ef 工具,我也可以在基础设施项目上进行迁移。

但是,当我这样做时,我收到以下错误

vscode ➜ /workspace/src/Ordering.Infrastructure (main) $ dotnet dotnet-ef migrations add init
Build started...
Build succeeded.
Startup project 'Ordering.Infrastructure.csproj' targets framework '.NETStandard'. There is no runtime associated with this framework,and projects targeting it cannot be executed directly. To use the Entity Framework Core .NET Command-line Tools with this project,add an executable project targeting .NET Core or .NET Framework that references this project,and set it as the startup project using --startup-project; or,update this project to cross-target .NET Core or .NET Framework. For more information on using the Entity Framework Tools with .NET Standard projects,see https://go.microsoft.com/fwlink/?linkid=2034781

这是基础设施项目的.csproj文件

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

   <ItemGroup>
    <ProjectReference Include="..\Ordering.Domain\Ordering.Domain.csproj" />
  </ItemGroup>

  <ItemGroup>
    <packagereference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </packagereference>
    <packagereference Include="Microsoft.EntityFrameworkCore.sqlServer" Version="3.1.0" />
    <packagereference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
    <packagereference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Properties\" />
  </ItemGroup>

</Project>

在这里遗漏了什么?为什么即使实现了 IDesignTimeDbContextFactory 我也无法进行迁移?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?