EF Core配置

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
否者可能报错如下:

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

posted @   ayatip  阅读(73)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示