在不同的项目上运行ef迁移脚本。

问题描述 投票:0回答:1

我有一个使用Entity Framework的.NET Core 3.1 Web App,该WebApp在一个项目Command.Api中,而EF与DBContext类在另一个项目Command.Core中。WebApp在一个项目Command.Api中,而EF与DBContext类在另一个项目Command.Core中。

我想通过运行command.Core来创建迁移脚本。

dotnet ef migrations script

不幸的是,我得到的错误是

System.Reflection.TargetInvocationException。异常已被调用目标抛出。 ---> System.NullReferenceException: 对象引用没有被设置为一个对象的实例。

当DBContext类与program.cs在同一个项目中时,脚本可以正常工作。

任何帮助将被感激

c# entity-framework .net-core asp.net-core-webapi ef-migrations
1个回答
0
投票

我们必须指定启动项目

dotnet ef migrations script --project Command.Core --startup-project Command.Api
© www.soinside.com 2019 - 2024. All rights reserved.