DbContext中只需要一个构造函数
点击查看代码
public DemoDbContext(DbContextOptions options) : base(options)
{
}
项目文件配置
api项目引用dbcontxt所在项目时,去掉dbcontext所在项目的项目文件中的<PrivateAssets>all</PrivateAssets>
否则会因为无法引用而报错
Your startup project 'Demo.API' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
加入--startup-project参数
dotnet ef --startup-project ..\Demo.API\ migrations add init
dotnet ef --startup-project ..\Demo.API\ database update