# Rider/DataGrip 可以用一下了吧 # Rider 常用快捷鍵 | 按鍵 | 用途 | 備註 | | -------- | -------- | -------- | | Shift * 2 / <br/> Ctrl + T | 全域的搜尋 | 最常使用 | | Alt + Enter / <br/> Ctrl + . | 小燈泡快捷鍵 | 重構 & 抽方法 & 刪除無用using 等等等 <br/><br/> 有時候會因為中文輸入法<br/>導致 `Ctrl + .` 跟 `。` 重疊故改用 Alt + Enter | | F2 / <br/> Ctrl + R , R | 改名 | 能用工具改就不要手動改 | | F12 | 進入方法 | | | Ctrl + F12 | 進入實作 | | | Shift + F12 | 列出有誰使用 (Reference) | | | ~~Ctrl + N~~ | 新增檔案|2025/11 此功能消失| | Ctrl + Shift + A | 新增檔案| (改)| | Alt + 1 | 方案總管 | | | Alt + Shift + = <br/> (Ctrl + W) |以選到的目標開始往外作選擇 | (Keymap:Extend Selection) | | Alt + Shift + . | 框起來的相同內容往下一個選 | | | Alt + Shift + , | 框起來的相同內容往上一個選 | | | Alt + Shift + ; | 選框起來的所有內容 | Keymap: Select All Occurrences | | Alt + \ | 選擇(列出)成員 | 有時候 Implement/Interface 太多會用 | | Alt + Home | 進入方法 Interface | | | Ctrl + Space | 彈出建議 | 但也是會有輸入法要調整的問題<br/>可以改用 Ctrl + J | | Ctrl + Shift + Space | 彈出可輸入的成員 | | | Shift + Enter | 同一頁開分頁 | 常誤觸講一下 | | Ctrl + K, K | 加入Bookmarks | 曾經追程式追到迷路的時候有用 | | = 搜尋 = | | | F3 | 下一個 | | | Shift + F3 | 上一個 | | | Ctrl + H | 替換文字 | | --- # Settings ## Inlay Hints ![image](https://hackmd.io/_uploads/SkLj4Eb3gg.png) 有時候 AutoMapper 提示灰字太長,已經影響閱讀的時候可以關掉。 ![image](https://hackmd.io/_uploads/SJy_SEb2le.png) ## 自己的調整 > Settings > Keymap > 使用 Visual Studio 想確認快捷鍵到底設定成甚麼功能時可用 `Find Actions by Shortcut` 搜尋 ![image](https://hackmd.io/_uploads/H1uUy4kdkg.png) ``` (我不常使用單行程式上下移動,自己改成方法的上下移動) - Move line up - [-] Alt + Up - Move line down - [-] Alt + Down - Next Method - [+] Alt + Down - Previoud Method - [+] Alt + Up (釘選大頭針) - Main Menu > Windows > Editor Tab > Pin Active Tab - [+] Alt + P ``` # 小燈泡 Alt + Enter (Ctrl + .) 可以示範一下,開發時的習慣操作。 ``` - Ctrl + N > 建 Interface , IUser - Task<IEnumerable<UserDataModel>> GetUser(); - Alt + Enter > 建立 UserDataModel - prop 宣告欄位 - Alt + Enter > 搬移檔案 Move to > UserDataModel.cs - Interface.GetUser ///加註解 - Interface > Alt + Enter > Create derived type 產生 class User - Alt + Enter > 搬移檔案 Move to > User.cs - User.cs > Alt + Enter > Implement missing member - User.GetUser > Alt + Enter > Copy documentation from base - Interface > Ctrl + Shift + R > 加入 string name > ctrl + N > string email ``` ## Ctrl + Shift + R (出發點為重構時) Change Signature 改變簽章 用於新增 or 更新 傳入參數時可以同時調整 Implement & Interface ![image](https://hackmd.io/_uploads/SyNfF7k_Jl.png) --- # EndPoint **⚠ 注意 目前 EndPoint 會自動去除 Action 的 Async** ![image](https://hackmd.io/_uploads/HJtL0q4o1g.png =60%x) ## 頁簽說明 1. HttpClient 1.1 `Submit Request` 直接觸發 1.2 `Open In Editor` 獨立檔案編輯(注意這個不存在於專案中,會存在於 Scratches and Consoles 內) 2. OpenAPI `POST` `Parameter(ex:CategoryParameter)` 欄位是看不到的, 需要依靠匯入 OpenAPI 格式才可以做到。 3. Documentation 可用來複製API說明 4. Examples --- ## 匯入現有的 OpenAPI Url > 後來想想其實跟直接開每一台主機 swagger 一樣, > 知道可以這樣做即可,效益沒有很大 ![image](https://hackmd.io/_uploads/H1w8v7kO1l.png) ![image](https://hackmd.io/_uploads/BkK_DmJ_ye.png) 匯入 自己 or外部 服務 /swagger/v1/swagger.json 後 就可以在 Rider 內直接看到 Swagger 頁面 --- ## HTTP Client (.http) 有教學影片可以看一下 > https://plugins.jetbrains.com/plugin/13121-http-client 1. 右上角 `Examples` 有基本範例 & 這個功能的介紹。 2. 左上角 可以直接插入 基本 `GET` 、`POST`。 3. 更多功能可以參考: `Open Http Client Help` 4. View > Tool Windows > [Structure] (https://www.jetbrains.com/help/rider/2024.3/Http_client_in__product__code_editor.html?Http_client_in__product__code_editor&keymap=Visual%20Studio%202022&utm_source=product&utm_medium=link&utm_campaign=RD&utm_content=2024.3#structure-tool-window) 可以看到 http 檔案內所有的方法。 ![image](https://hackmd.io/_uploads/rJiz8AUsJe.png =40%x) ![image](https://hackmd.io/_uploads/BJBdNB0DJg.png =40%x) ### 1.基本使用 ``` # 註解 ### 取得會員相簿明細 GET {{HostAddress}}/api/ws/AI/Album/2/Pictures Authorization: Bearer {{AuthToken}} ``` > 💡 小提醒: 如果公司內的服務是只支援 HTTP/1.1 預設情況下, 打API通常會出現錯誤訊,這個時候只要在最後明確指定就可以了。 範例:GET https://xxxx.com/api/xxx HTTP/1.1 --- ### 2.變數宣告 ``` # 變數宣告 :會替換此檔案內所有的變數 @id = 35052 ### 取得社區 GET {{HostAddress}}/api/v1/Community/{{id}} ### 取得社區Id含名稱列表 POST {{HostAddress}}/api/v1/Community Content-Type: application/json # 要標記 Content-Type: application/json 就可以加入 Body {} { "county": "台北市" } ``` ### 3.環境變數 加入檔案 http-client.env.json > 注意事項: > 2025/02 > 1. ws社區情境:正式 及 測試 環境要使用 `http://` ,不然會出現 > 錯誤訊息: `java.nio.channels.ClosedChannelException` ``` { "local": { "HostAddress": "https://localhost:44341" }, "dev": { "HostAddress": "http://ws-community-t.woody.tw" }, "productioin": { "HostAddress": "http://ws-community.woody.tw" } } ``` 如果有 AuthToken 但不想被加入版控,使用 `Add Enviornment to Private File` 就會產生 http-client.private.env.json 。 Rider 自己的 Git 工具會排除這個檔案 但使用 Fork 就要自己加 `ignore` --- ### 4.與 Visual Studio 版本差異 #### 4.1 觸發 API "前" 要作的行為 `< {% %}` 情境: 1. 針對單一 API 想要自訂變數時使用 2. 使用 js 方法 UrlEncode 文字後填入變數 ``` ### 使用建商地址取得建商基本資料列表。 <{% const address = "臺北市大安區市民大道3段178號8樓"; const encodedAddress = encodeURIComponent(address); request.variables.set("address", encodedAddress) %} GET {{HostAddress}}/api/v1/Builder/GetCompanyBasicListByAddressAsync/{{address}} ``` --- #### 4.2 觸發 API "後" 要作的行為 `> {% %}` 撰寫簡易的測試案例 注意:是使用 js 來撰寫測試。 #### 目前常用的檢查 ##### 1.ResponseStatus 確認 ``` client.test("驗證回傳狀態必須為 200", function () { client.assert(response.status === 200, "Response status is not 200"); }); ``` ##### 2. 回傳欄位 是否存在 ( != null) ``` client.test("response.body 欄位必須符合", function () { client.assert(response.body.apiVersion != null, "缺少 apiVersion 欄位"); client.assert(response.body.method != null, "缺少 method 欄位"); client.assert(response.body.status != null, "缺少 status 欄位"); client.assert(response.body.id != null, "缺少 id 欄位"); client.assert(response.body.data != null, "缺少 data 欄位"); }); ``` ##### 3. 回傳欄位 必須是 Array ``` client.test("data 陣列必須存在且至少有一筆資料", function () { client.assert(Array.isArray(response.body.data), "必須是陣列"); client.assert(response.body.data.length > 0, "陣列必須至少有一筆資料"); }); ``` ##### 4. 回傳欄位 不可以是{} ``` client.test("驗證回傳 data 必須不為 {}", function () { client.assert(Object.keys(response.body.data).length > 0, "不可為空"); }); # 範例 { "id": "00aeb5e8-1b4f-4e22-83b2-1af84957d10e", "apiVersion": "1", "method": "/api/v1/CommunityDetail/dictionary.POST", "status": "Success", "data": {} } ``` --- # 好用套件(PlugIn) | 名稱 | 用途 | | -------- | -------- | |[CognitiveComplexity](https://plugins.jetbrains.com/plugin/12024-cognitivecomplexity) | 顯示程式複雜度| |[Translation](https://plugins.jetbrains.com/plugin/8579-translation)| 翻譯工具| |[CodeGlance Pro](https://plugins.jetbrains.com/plugin/18824-codeglance-pro) | 習慣程式碼右邊有"地圖" | |[Kilo Code](https://plugins.jetbrains.com/plugin/28350-kilo-code) | 目前(2025/10/23) 體感在 Rider 上最好用的 AI Agent。<br/> Cline 也有在關注,但因為目前不能開多個專案有Bug。 | --- # DataGrip(Rider-Database) > Rider 內可以使用 DataBase 但會綁定到一個 sln 的設定, 但開新專案設定就消失了,所以轉而使用 [DataGrip](https://www.jetbrains.com/datagrip)。 > 以下知識都來自 [教學影片](https://www.youtube.com/watch?v=U5SOD-eeK50&list=PLQ176FUIyIUaY35luxpLwwivq0Z4EPbqN) & 幾周的使用心得 ``` - Woody@xxxxxx-DEV(Host) - DBName - dbo - tables - 資料表在這 ``` 1. `Services > Database` 頁簽中可以看到歷史查詢資料 2. `Ctrl + Enter` 可以執行被框起來的 SQL 語法 3. 優點: * 建議文字出現的蠻快的 * 可以搭配 Copilot 一起使用 4. 在 * 號上 Alt + Enter 選擇 Expand Column list 可以把欄位展開 因為預設 SQL Script > Select All rows from Table 會是 Select * From xxx ![image](https://hackmd.io/_uploads/SJj4JvAqgx.png) 5. Autoscroll from Editor 可以自動跳到那張表,跟 Rider 追檔案一樣 ![image](https://hackmd.io/_uploads/HyXXUZwCee.png) 6. 習慣看到資料表 & 欄位的描述 所以開啟 Comments (但現在都要搭配 Ctrl+F5 重整才會顯示) ![image](https://hackmd.io/_uploads/S1-ZdGDRxl.png) ## Database Explorer 當資料來源越來越多時就會想要分組 可以在資料庫上使用 F6 ( Move To Folder...) 分類 ![image](https://hackmd.io/_uploads/B1qNGd7lWl.png) ## 快捷鍵 > Keymap 使用 Windows 預設 | 按鍵 | 用途 | 備註 | | -------- | -------- | -------- | | Ctrl + Enter | 執行查詢 | | | Ctrl + Shift + Q | 開新查詢語法 | | | Shift + F6 | 改名稱 | 預設是 `Project File` <br/>可以用來改 Alias Name <br/>注意 !!<br/>這是可以直接改到真實資料表明稱的(要非常注意自己選到什麼) | | Ctrl + F6 | 編輯資料表 | | Ctrl + W | 往外選擇(有點難解釋可以自己操作) Extend Selection | Ctrl + / | 註解 | | Ctrl + Alt + L | 格式化文件| | Alt + Shift + B | 等同 Autoscroll from Editor | | | Ctrl + Shift + U | 框起來的內容大小寫轉換 | | | Ctrl + Q | 快速看欄位型態(描述) | Quick Documentation | | Ctrl + F12 | 編輯模式可以選擇要看的欄位(按空白決定顯示隱藏) | | | Ctrl + Shift + F12 | 收起所有工具視窗 | | ## 查詢區塊 ### 查詢預設值 預設就算查詢 * 也會是1000,是可以自己調整預設值的,選要的筆數後點 `Set as Defaul` 就可切換。 ![image](https://hackmd.io/_uploads/SJoRjMw0ge.png) ### Update 欄位 直接調整欄位 後點擊 ![image](https://hackmd.io/_uploads/HyBq3MPRxx.png) (或是 Ctrl + Enter) ![image](https://hackmd.io/_uploads/Bk882zvRxg.png) ## 執行計畫 (Explain Plain) 要觀察的語法右鍵 > Explain Plan (也可以執行多個查詢,但看起來不像SSMS會顯示誰比較優,要用 Cost 觀察) ![image](https://hackmd.io/_uploads/HJ6e4ZVgWl.png) 顯示關聯圖 ![image](https://hackmd.io/_uploads/H17OizvRgg.png) ![image](https://hackmd.io/_uploads/S1_DYlnlbx.png) 1. Index 如果有使用到會列出命中的,也會有 🗝️ 提示。 2. Rows 查詢出來的筆數 3. cost 總成本(相對百分筆) <-目前可以執行index後,用來觀察這個數字有沒有改變。 4. 如果明顯缺少 Index 也會直接提供建議 ⚠️。 ### Index | 查詢動作 (Action) | 中文名稱 | 效能評估 | 說明與建議 | | :--- | :--- | :--- | :--- | | **Full Scan (Table Scan)** | 全表掃描 | 🔴 優先處理 | 效能最差。資料庫必須讀取每一行資料,通常是因為完全沒有可用索引。 | | **Index Scan** | 索引掃描 | 🟡 成本較高 | 遍歷整個索引樹。通常發生在模糊查詢(如 `%abc`)或欄位型別不匹配時。 | | **Full Index Scan** | 叢集索引掃描 | 🟡 成本較高 | 掃描整個叢集索引(即整張表的資料)。常發生在 `SELECT *` 且無特定篩選條件時。 | | **Index Seek** | **索引尋找** | 🟢 效率極高 | **優化目標。** 利用 B-Tree 結構快速定位資料點,I/O 消耗最小,速度最快。 | --- | 查詢動作 (Action) | 中文名稱 | 效能評估 | 說明與建議 | | :--- | :--- | :--- | :--- | |**Key Lookup**| | |沒有 Include 回表取其他欄位 | --- #### 編輯 (Ctrl+F6) ![image](https://hackmd.io/_uploads/HkhHPNGV-x.png) ![image](https://hackmd.io/_uploads/rkw0OEMN-e.png) 1. Columns: `Where` & `Join` & `ORDER BY` 會使用到的欄位。 2. Include Columns:SELECT 中需要的列。 3. PreView:有任何異動都會在這邊產生相對應的語法。 > 核心概念:Columns 是找資料的鑰匙,Include Columns 是帶出來的額外資料。 #### SQL Generator ( Ctrl + Alt + G ) 直接產生 相關 SQL 語法 ![image](https://hackmd.io/_uploads/ByON54z4bx.png) ![image](https://hackmd.io/_uploads/HkHI5NMNbe.png) --- ## SQL Format > 自己習慣 SELECT & 型態 是大寫 , 欄位是第一個字大寫 預設 Format 完都是小寫, 這個介面都會閃爍畫面讓你知道要改動的是甚麼很方便。 Settings > Editor > Code Style > SQL > General ![image](https://hackmd.io/_uploads/rkwgzWVgbg.png) 1. KeyWord (SELECT) - 全大寫 2. Identifiers (欄位名稱) - 第一個字大寫 3. Built-in types (型態) - 全大寫 4. Aliased (別名) - 全小寫 --- ## 複製(匯出)資料 > 有時候會想要把資料 當作 Insert 資料 / 當作Where條件/甚至是Excel/CSV 等等 把結果選擇起來複製後,就會產生對應的語法 ![image](https://hackmd.io/_uploads/ryji0UKeZx.png) ### 先選擇想要的格式 ![image](https://hackmd.io/_uploads/rypWyPYg-l.png) #### SQL Inserts ``` INSERT INTO Northwind.dbo.Categories (CategoryName, Description) VALUES (N'Beverages', N'Soft drinks, coffees, teas, beers, and ales'); INSERT INTO Northwind.dbo.Categories (CategoryName, Description) VALUES (N'Condiments', N'Sweet and savory sauces, relishes, spreads, and seasonings'); INSERT INTO Northwind.dbo.Categories (CategoryName, Description) VALUES (N'Confections', N'Desserts, candies, and sweet breads'); INSERT INTO Northwind.dbo.Categories (CategoryName, Description) VALUES (N'Dairy Products', N'Cheeses'); INSERT INTO Northwind.dbo.Categories (CategoryName, Description) VALUES (N'Grains/Cereals', N'Breads, crackers, pasta, and cereal'); INSERT INTO Northwind.dbo.Categories (CategoryName, Description) VALUES (N'Meat/Poultry', N'Prepared meats'); INSERT INTO Northwind.dbo.Categories (CategoryName, Description) VALUES (N'Produce', N'Dried fruit and bean curd'); INSERT INTO Northwind.dbo.Categories (CategoryName, Description) VALUES (N'Seafood', N'Seaweed and fish'); ``` #### Where Clause 複製後會直接變成條件格式 ``` CategoryName IN (N'Beverages', N'Condiments', N'Confections', N'Dairy Products', N'Grains/Cereals') ``` ## 例外處理 先前舊版也不能執行 .sql 但因為不影響使用就不管它 但目前升級到 2025.3 後預設就不是 console 而是真實建立 .sql 檔案 參考:https://youtrack.jetbrains.com/issue/DBE-16116?_gl=1*je52kb*_gcl_au*NjkwOTI0NzM2LjE3NTc0NjkzMDU.*FPAU*NjkwOTI0NzM2LjE3NTc0NjkzMDU.*_ga*Njg0MDIxNDQ5LjE3MTM3NTQyMDE.*_ga_9J976DJZ68*czE3NjQ3MzA3NzckbzEzNSRnMSR0MTc2NDczMDg4MiRqNjAkbDAkaDA.&_cl=MTsxOzE7b3hxODBnYXhLeXhMMkhYeU9qN21EQ2F6RGlLWEl1OXVKZmZLRHYxTXpGZmhzSXRVdWNhRzQ0MnA3V2NGSThFWTs= 調整 `SQL` 增加 File Name `*.sql` 後, 就可以有提示字 & 執行查詢了 ![image](https://hackmd.io/_uploads/HyEFiXp-Zg.png) --- --- # 其它紀錄 ## User Secrets 在指定的專案 右鍵 > Tools > .NET User Secrets csproj 也會自動加入 `<UserSecretsId></UserSecretsId>` ![image](https://hackmd.io/_uploads/SJBmV0-Fye.png) ## User Secrets File > 目前僅 Visual Studio 可使用 > 持續關注 > https://youtrack.jetbrains.com/issue/IJPL-65391/Add-in-HTTP-Client-support-for-secrets-coming-from-secrets-vaults-Azure-Key-Vault-AWS-Secrets-Manager-GCP-Secret-Manager- 參考文章: https://learn.microsoft.com/zh-tw/aspnet/core/test/http-files?view=aspnetcore-9.0#aspnet-core-user-secrets ``` { "config": { "AuthToken": "eyJhbGciOiJSUzI....." } } ``` ### http-client.env.json 取得 secret 的固定寫法參考 "AuthToken" ``` { "local": { "HostAddress": "https://localhost:44338", "AuthToken": { "provider": "AspnetUserSecrets", //固定寫法 "secretName": "config:AuthToken" // } } } ```