程式設計
C# MVC
資料庫
特色:可以直接讀取 SQLite 資料庫 有中文介面
https://sqlitebrowser.org/
主畫面
新增、編輯資料表定義schema
新增、編輯資料列
Install latest Toolbox
Once per Visual Studio edition (daily build at https://github.com/ErikEJ/SqlCeToolbox/wiki/Release-notes )
Install SQLite in GAC
下載
sqlite-netFx46-setup-bundle-x64-2015-1.0.115.5.exe 並安裝,該台電腦安裝一次即可,其他程式可共用
參考來源
Once per machine. Download the latest sqlite-netFx46-setup-bundle-x86-2015-1.0.xxx.0.exe (from https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki)
Select "Full Installation"
Select: Install the assemblies into the global assembly cache - Install VS designer components
* sqlite (這邊是3.13版)
### sqlite (這邊是3.13版)
~~ https://www.nuget.org/packages/SQLite/3.13.0?_src=template
System.Data.SQLite 相依於 enfityframework 6.3以上,寫這篇的時候,enfityframework繁體中文套件只有6.2,直接升級ef有相容性問題升不上去,因此要 手動刪掉EntityFramework.zh-Hant 中文套件,才能把ef核心升級上去(升級之後可以再回頭安裝中文套件不用擔心),升到 ef 6.3 才能安裝這兩個關鍵的元件
System.Data.SQLite.SQLite
System.Data.SQLite.EF6
裝 System.Data.SQLite.SQLite 會順便裝這一堆
要安裝的是 System.Data.SQLite ( https://www.nuget.org/packages/System.Data.SQLite/1.0.113.1?_src=template )
,要注意不要安裝到 Microsoft.Data.Sqlite,會有相衝問題,不小心裝到可以從nuget直接移除掉
在要建立 Model 的資料夾點選右鍵 > 新增項目 > 在新開的視窗選 [新增 ADO.NET 實體資料模型] (注意下方的名稱不要衝突囉)
這次的目標是從資料庫生成model,,所以在這個視窗選 [來自資料庫的 EF Designer] ,如果想使用code First的可以用 code first的方式,但在這篇不討論作法
[新增連接] > 資料來源選 [變更]
變更資料來源選擇 [SQLite Provider],如果沒有這個選項,代表前面安裝元件有問題,請確認是否都正常安裝了
範例1,在C#程式裡控制
String currentPath = System.IO.Path.GetDirectoryName( Application.ExecutablePath );
範例2 在web.config
使用 Data Source=|DataDirectory|mydb.db
這樣就代表資料庫在專案資料夾的 /App_Data/mydb.db
https://www.itdaan.com/tw/c038ccba03ca68debe5bdd0d97784bf1
https://docs.microsoft.com/zh-tw/ef/core/get-started/?tabs=visual-studio
https://blog.csdn.net/catshitone/article/details/80320493
https://ronsun.github.io/content/20190907-use-sqlite-with-ef-and-vs2017.html
https://github.com/ErikEJ/SqlCeToolbox/wiki/EF6-workflow-with-SQLite-DDEX-provider
[研究] NuGet 無法解析相依性。'EntityFramework 6.4.0' 與 'EntityFramework.zh-Hant 6.2.0 條件約束: EntityFramework (= 6.2.0)' 不相容。
http://shaurong.blogspot.com/2019/12/nuget-entityframework-640.html