From b71e1294af459987fcbddbdb92ab73dfeed2c331 Mon Sep 17 00:00:00 2001 From: "Min.Ling" Date: Wed, 25 Nov 2020 17:42:13 +0800 Subject: [PATCH 1/4] Update Entity-Framework-Core-Other-DBMS.md remove "Change the Migrations DbContext" plate, because no need to manually set database provider after v2.9+ add "Change the Migrations DbContext Factory" plate, because the switch to MySQL, we also need to modify the DbContextOptionsBuilder mark "DBMS restrictions" plate, Add history modification record --- .../Entity-Framework-Core-Other-DBMS.md | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md b/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md index fb8ad15787..a60732f1ee 100644 --- a/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md +++ b/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md @@ -62,22 +62,25 @@ MySQL连接字符串与SQL Server连接字符串不同. 所以检查你的解决 通常需要更改 `.DbMigrator` 和 `.Web` 项目里面的 `appsettings.json` ,但它取决于你的解决方案结构. -## 更改迁移DbContext +## 更改迁移DbContext Factory -MySQL DBMS与SQL Server有一些细微的差异. 某些模块数据库映射配置(尤其是字段长度)会导致MySQL出现问题. 例如某些[IdentityServer模块](Modules/IdentityServer.md)表就存在这样的问题,它提供了一个选项可以根据你的DBMS配置字段. +启动模板包含***YourProjectName*MigrationsDbContextFactory**,这是EF Core控制台命令所必须的类(比如[Add-Migration](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#generating--running-migrations)和[Update-Database](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#generating--running-migrations)),在切换到MySql数据库时,我们同时也需要修改`DbContextOptionsBuilder` -启动模板包含*YourProjectName*MigrationsDbContext,它负责维护和迁移数据库架构. 此DbContext基本上调用依赖模块的扩展方法来配置其数据库表. +在 *YourProjectName*MigrationsDbContextFactory 类中找到以下代码: -打开 *YourProjectName*MigrationsDbContext 更改 `builder.ConfigureIdentityServer();` 行,如下所示: +````csharp +var builder = new DbContextOptionsBuilder() + .UseSqlServer(configuration.GetConnectionString("Default")); +```` + +将其替换为: ````csharp -builder.ConfigureIdentityServer(options => -{ - options.DatabaseProvider = EfCoreDatabaseProvider.MySql; -}); +var builder = new DbContextOptionsBuilder() + .UseMySql(configuration.GetConnectionString("Default")); ```` -然后 `ConfigureIdentityServer()` 方法会将字段长度设置为超过MySQL的限制. 如果在创建或执行数据库迁移时遇到任何问题请参考相关的模块文档. +如果在创建或执行数据库迁移时遇到任何问题,请参考相关模块文档 ## 重新生成迁移 @@ -105,5 +108,6 @@ builder.ConfigureIdentityServer(options => options.DatabaseProvider = EfCoreDatabaseProvider.MySql; }); ``` +v2.9+版本无需手动设置 ([版本历史](https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerModelBuilderConfigurationOptions.cs)) -相关讨论: https://github.com/abpframework/abp/issues/1920 \ No newline at end of file +相关讨论: https://github.com/abpframework/abp/issues/1920 From 76a7fdcfcbd5568d6fc636ef0f38073f03d9c769 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 14 Jan 2021 09:15:09 +0800 Subject: [PATCH 2/4] Update docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md Co-authored-by: Qingxiao Ren --- docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md b/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md index a60732f1ee..93b8a52db9 100644 --- a/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md +++ b/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md @@ -64,7 +64,7 @@ MySQL连接字符串与SQL Server连接字符串不同. 所以检查你的解决 ## 更改迁移DbContext Factory -启动模板包含***YourProjectName*MigrationsDbContextFactory**,这是EF Core控制台命令所必须的类(比如[Add-Migration](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#generating--running-migrations)和[Update-Database](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#generating--running-migrations)),在切换到MySql数据库时,我们同时也需要修改`DbContextOptionsBuilder` +启动模板包含***YourProjectName*MigrationsDbContextFactory**类,这是EF Core控制台命令所必须的类(比如[Add-Migration](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#generating--running-migrations)和[Update-Database](https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/#generating--running-migrations)),在切换到MySql数据库时,我们同时也需要修改`DbContextOptionsBuilder` 在 *YourProjectName*MigrationsDbContextFactory 类中找到以下代码: From 16d0438d427de333eda84479402fe5b7d49474e4 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 14 Jan 2021 09:15:30 +0800 Subject: [PATCH 3/4] Update docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md Co-authored-by: Qingxiao Ren --- docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md b/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md index 93b8a52db9..a779499f53 100644 --- a/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md +++ b/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md @@ -69,7 +69,7 @@ MySQL连接字符串与SQL Server连接字符串不同. 所以检查你的解决 在 *YourProjectName*MigrationsDbContextFactory 类中找到以下代码: ````csharp -var builder = new DbContextOptionsBuilder() +var builder = new DbContextOptionsBuilder() .UseSqlServer(configuration.GetConnectionString("Default")); ```` From 9f93143d146b9bba62079fb908183b45d739c324 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 14 Jan 2021 09:16:04 +0800 Subject: [PATCH 4/4] Update docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md Co-authored-by: Qingxiao Ren --- docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md b/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md index a779499f53..56a37396ea 100644 --- a/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md +++ b/docs/zh-Hans/Entity-Framework-Core-Other-DBMS.md @@ -76,7 +76,7 @@ var builder = new DbContextOptionsBuilder() 将其替换为: ````csharp -var builder = new DbContextOptionsBuilder() +var builder = new DbContextOptionsBuilder() .UseMySql(configuration.GetConnectionString("Default")); ````