-
Notifications
You must be signed in to change notification settings - Fork 0
Home
蔡家滄 edited this page May 23, 2017
·
17 revisions
Welcome to the nTinyPass wiki!
- nTinyPass 是一個極輕量化的 DTO (Data Transfer Object) 擴充程式 , 目標為自動轉換 DataReader/DataTable 為指定物件.
- 處理 Property and Filed 允許對 readonly 進行寫入.
如下列範例 👍 Example Pass_001
讀取所有資料列至指定資料可型別陣中.
SqlCommand cmd = new SqlCommand("select * from Categories", Connection); var Categories = nTinyPass<CategoryEntry>.QueryAll(cmd.ExecuteReader()); foreach(var category in Categories) { Debug.Print($"{category}"); }
使用匿名型別(anonymous type) 取資料. 這樣子就不需要為了取回少量的資料欄位去定義一個不常用型別, 光是型別名稱命名就是一個頭痛的問題.
see Example Pass_002
SqlCommand cmd = new SqlCommand("select * from Categories", Connection); var category = new { CategoryID = 0, CategoryName = "" }; using (var dr = cmd.ExecuteReader()) { if (dr.Read()) dr.QueryFill(category); }