ABP從入門到精通(2):aspnet-zero-core 使用MySql資料庫
關於 asp.net zero core 項目的啟動及說明,請觀看我前面的博文 http://www.cnblogs.com/stulzq/p/7237153.html
本操作對於ABP默認項目應該也是適用的!
一.移除默認的SqlServer相關程序包
需要移除「MyCompanyName.AbpZeroTemplate.EntityFrameworkCore」 項目 Microsoft.EntityFrameworkCore.SqlServer、Microsoft.EntityFrameworkCore.Design 兩個程序包
二.添加MySql程序包
對項目 「MyCompanyName.AbpZeroTemplate.EntityFrameworkCore」 添加程序包「Pomelo.EntityFrameworkCore.MySql.Design」
三.更改項目源代碼
以前代碼更改都是在 「MyCompanyName.AbpZeroTemplate.EntityFrameworkCore」 項目下進行:
1.AbpZeroTemplateDbContextConfigurer.cs
1 public static class AbpZeroTemplateDbContextConfigurer
2 {
3 public static void Configure(DbContextOptionsBuilder<AbpZeroTemplateDbContext> builder, string connectionString)
4 {
5 builder.UseSqlServer(connectionString);
6 }
7 }
改為:
1 public static class AbpZeroTemplateDbContextConfigurer
2 {
3 public static void Configure(DbContextOptionsBuilder<AbpZeroTemplateDbContext> builder, string connectionString)
4 {
5 builder.UseMySql(connectionString);
6 }
7 }
四.遷移資料庫
1.刪除下圖的cs文件
2.生成項目
3.更改連接字元串
連接字元串都是放在 appsettings.json
4.執行遷移操作
請確認MySql資料庫開啟,打開程序包管理器控制台,選中項目「MyCompanyName.AbpZeroTemplate.EntityFrameworkCore」,輸入命令
Add-Migration init
遷移成功會出現如下提示:
查看Migrations文件夾會增加幾個cs文件
5.生成項目
6.執行命令「Update-Database」
生成資料庫成功會出現如下提示:
看看資料庫已經成功生成:
五.啟動項目
登錄成功!
六.使用項目自帶的工具遷移
前面的博文說過,項目「MyCompanyName.AbpZeroTemplate.Migrator」是自帶的遷移工具,下面咱門來測試一下
1.首先回滾一下上面生成資料庫的操作,直接刪除資料庫
2.更改連接字元串
3.運行項目
生成成功!
如果你覺得寫的不錯,請點一下下面的「推薦」,這是對我分享技術經驗的支持,謝謝!↓↓↓↓↓↓↓↓↓↓↓
※UglifyJS——對你的js做了什麼
※使用 node+backbone搭建個人博客系統
※SVN分支/主幹Merge操作小記
※多線程之策略模式
※利用Fiddler修改請求信息通過Web API執行Dynamics 365操作(Action)實例
TAG:科技優家 |
※Spring Boot與Kotlin 使用MongoDB資料庫
※2019年NoSQL 資料庫 TOP 15:MongoDB、微軟、Couchbase、AWS、谷歌、Redis Labs
※雲資料庫TencentDBforPostgreSQL
※SpringBoot整合MyBatis,MySql之從前台頁面到資料庫的小Demo
※Oracle 資料庫中enq:TX-index contention等待時間淺析
※雲資料庫TencentDBforMongoDB
※雲資料庫TencentDBforMariaDB
※SpringBoot使用資料庫
※力壓 MongoDB、Redis,PostgreSQL 蟬聯「年度資料庫」!
※雲資料庫TencentDBforRedis
※sqlite-utils:用於構建SQLite資料庫的Python庫和命令行工具
※Gson+pulltorefer+資料庫+httpurlconnection+非同步(更新)
※雲資料庫TencentDBforMySQL
※開源資料庫 PostgreSQL、MariaDB 和 SQLite 的對比
※Google 的雲端資料庫Cloud SQL:開始支持 PostgreSQL
※SpringBoot使用H2內嵌資料庫
※谷歌的Firebase爆大禍,泄漏了113GB的iOS/Android用戶資料!
※雲資料庫TencentDforSQLServer
※雲資料庫TencentDforMemcached
※使用Django連接Oracle 11g資料庫