diff --git a/C%23.md b/C%23.md index 21072ba..67f6b7e 100644 --- a/C%23.md +++ b/C%23.md @@ -67,4 +67,64 @@ select c ``` ## ## VS2022 -### 安裝 +### 安裝 [下載連接](https://visualstudio.microsoft.com/zh-hant/vs/compare/) +### 下載後,若單純架設網站選擇ASP.NET 與 Node.js(之後寫Vue會用到) +### 若需要維護Winform 或是WPF 則選擇.NET桌面開發 +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%871.png) + +### 若需要快速建立,則直接使用我提供的DEMO去做開發 +### 建立新專案 +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%872.png) + +### 選擇版本 (這邊以.NET6做教學 目前最新的.NET8) +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%873.png) + +### 啟動 +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%874.png) + +### 安裝套件包(NuGet) +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%875.png) +### 設定資料庫連線 +#### 於appsettings.json 中加入 +``` +//連接MYSQL + "ConnectionStrings": { + "tarefasConnection": "server=140.125.21.65;port=3307;uid=VIP125;pwd=@VIPvip125;database=VIP125" + } +``` +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%876.png) + +#### 於Program.cs中加入設定 +``` + builder.Services.AddDbContext(opt => +{ + string connectionString = builder.Configuration.GetConnectionString("tarefasConnection"); + var serverVersion = ServerVersion.AutoDetect(connectionString); + opt.UseMySql(connectionString, serverVersion); +}); +``` +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%877.png) +### 建立與資料庫table的連線 +#### 創建Model + 建議將創建的Model名稱第一個字大寫,資料庫內部資料表名用小寫,這樣較好對比 + Model內容需要跟資料表的欄位名稱相對應 + +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%879.png) +#### 創建Services + Haskey指的是不會重複的 + 像是身份證字號這種的就不會重複 +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%878.png) + +### 創建控制器 +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8710.png) +### 創建出來的頁面 +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8711.png) + +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8712.png) + +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8713.png) + +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8714.png) + +![](http://140.125.21.65:8418/Education/Backend/raw/branch/master/C_shape/img/%E5%9C%96%E7%89%8715.png) +