首先,在项目中安装 MySql.Data 包,这是用于连接和查询 MySQL 数据库的必要库。
然后,在项目的 Startup.cs 文件的 ConfigureServices 方法中,添加以下代码以注册 MySQL 数据库连接服务:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));