移除SQL Server相关包
- 在EntityFrameworkCore项目下移除包Microsoft.EntityFrameworkCore.SqlServer、Microsoft.EntityFrameworkCore.Design
添加Mysql相关包
- 在EntityFrameworkCore项目下添加包Pomelo.EntityFrameworkCore.MySql、Pomelo.EntityFrameworkCore.MySql.Design
修改EntityFrameworkCore源代码
public static void Configure(DbContextOptionsBuilder<DbContext> builder, string connectionString)
{
//builder.UseSqlServer(connectionString);
builder.UseMySql(connectionString);
}
public static void Configure(DbContextOptionsBuilder<DbContext> builder, DbConnection connection)
{
//builder.UseSqlServer(connection);
builder.UseMySql(connection);
}
修改连接字符串
- 修改host层的appsetting.cs文件
"ConnectionStrings": {
//"Default": "Server=localhost; Database=SignalRChatDb; Trusted_Connection=True;"
"Default": "Server=localhost; Database=SignalRChatDb; User ID=root; Password=123456; port=3306"
},
迁移数据库
-
添加migration
add-migration "init" -c ApplicationDbContext
-
更新数据库
update-database