ABP切換到EF Core SQLite提供程序
替換Volo.Abp.EntityFrameworkCore.SqlServer包
解決方案中的 .EntityFrameworkCore
項目依賴於 Volo.Abp.EntityFrameworkCore.SqlServer NuGet包. 刪除這個包。
設置默認項目:.EntityFrameworkCore
install-package Volo.Abp.EntityFrameworkCore.SQLite
替換模塊依賴項
在 .EntityFrameworkCore
項目中找到 YourProjectName*EntityFrameworkCoreModule 類, 刪除 DependsOn
attribute 上的typeof(AbpEntityFrameworkCoreSqlServerModule)
, 添加 typeof(AbpEntityFrameworkCoreSqliteModule)
(或者替換 using Volo.Abp.EntityFrameworkCore.SqlServer;
爲 using Volo.Abp.EntityFrameworkCore.Sqlite;
).
UseSqlite()
查找你的解決方案中 UseSqlServer()
調用,替換爲 UseSqlite()
. 檢查下列文件:
.EntityFrameworkCore
項目中的YourProjectNameEntityFrameworkCoreModule.cs..EntityFrameworkCore
項目中的YourProjectNameMigrationsDbContextFactory.cs.
根據你的解決方案的結構,你可能發現更多需要改變代碼的文件.
更改連接字符串
SQLite連接字符串與SQL Server連接字符串不同. 所以檢查你的解決方案中所有的 appsettings.json
文件,更改其中的連接字符串.
"ConnectionStrings": {
"Default": "Data Source=D:\\down\\2020-01\\IFMS_tiered\\db\\abp.db"
}
通常需要更改 .DbMigrator
和 .Web
項目裏面的 appsettings.json
,但它取決於你的解決方案結構.
重新生成遷移
- 刪除
.EntityFrameworkCore.DbMigrations
項目下的Migrations文件夾,並重新生成解決方案. - 在包管理控制檯中運行
Add-Migration "Initial"
(在解決方案資源管理器選擇.DbMigrator
(或.Web
) 做爲啓動項目並且選擇.EntityFrameworkCore.DbMigrations
做爲默認項目).
這將創建一個配置所有數據庫對象(表)的數據庫遷移.
運行 .DbMigrator
項目創建數據庫和初始種子數據.
運行應用程序
IdentityServer、Host、Web項目