ABP EntityFramework 切换为 PostgreSQL / MySQL 支持

1.引用 Npgsql.EntityFrameworkCore.PostgreSQL、Pomelo.EntityFrameworkCore.MySql NuGet 包至 EntityFrameworkCore 项目;

2.在 DbContextConfigurer 类中使用 builder.UseNpgsql(connectionString); 并引入 Npgsql 命名空间或 builder.UseMySql(connection); 引入 MySql.Data.MySqlClient 命名空间;

3.修改连接字符串,两种数据库的连接字符串其实可以通用也可以写成下面的格式;

PostgreSQL:host=localhost;port=8100;database=databaseName;userid=postgres;pwd=password;

MySQL:server=localhost;port=8100;database=databaseName;uid=root;pwd=password;Character Set=utf8;

4.重新生成迁移代码并更新数据库;

就这样 EntityFramework 就可以顺利的支持 PostgreSQL、MySQL 数据库了。

迁移与数据库更新命令:

Add-Migration init -C HostDbContext

Update-Database init -C HostDbContext

原文地址:https://www.cnblogs.com/fxck/p/13076692.html