自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

自己寫數(shù)據(jù)庫訪問ORM

數(shù)據(jù)庫 SQL Server
目前,往上有很多優(yōu)秀的ORM,但和Csla緊密結(jié)合還沒找到合適的。出于需要,自己動手寫了一個。主要優(yōu)點在于,實現(xiàn)了直接通過DataReader填充業(yè)務類數(shù)據(jù)。IF使用簡單,只要在業(yè)務類上標記特性TableClass、FieldDescription即可將業(yè)務類和數(shù)據(jù)庫建立映射關(guān)系。

 下面看一個例子:

現(xiàn)在有一個用戶信息的表:E-R圖如下:

要實現(xiàn)該表的數(shù)據(jù)庫新增、修改、查詢功能,需要實現(xiàn)下面兩個業(yè)務類:

  1. using Csla; 
  2. using IF.CslaCore; 
  3. using IF.OrmCore.DataSchema; 
  4. using System; 
  5. using System.Collections.Generic; 
  6. using System.ComponentModel; 
  7. using System.Linq; 
  8. using System.Text; 
  9. using System.Threading.Tasks; 
  10.  
  11. namespace IF.SysUser.Business 
  12.     [Serializable
  13.     [TableClass(FriendlyName="用戶信息表",TableName="SYS_USER")] 
  14.     public class SysUser : IfBusiness<SysUser> 
  15.     { 
  16.         private static readonly PropertyInfo<string> SUR_IDProperty = RegisterProperty<string>(c => c.SUR_ID); 
  17.  
  18.         [DisplayName("SUR_ID")] 
  19.         [FieldDescription(IsPrimaryKey=true,ColumnName="SUR_ID",FriendlyName="SUR_ID",NeedUpdate=true)] 
  20.         public string SUR_ID { get; set; } 
  21.  
  22.         private static readonly PropertyInfo<string> UserNameProperty = RegisterProperty<string>(c => c.UserName); 
  23.         [DisplayName("登錄名")] 
  24.         [FieldDescription(ColumnName="SUR_USERNAME",FriendlyName="登錄名",NeedUpdate=true)] 
  25.         public string UserName { get; set; } 
  26.  
  27.  
  28.         private static readonly PropertyInfo<string> NameProperty = RegisterProperty<string>(c => c.Name); 
  29.         [DisplayName("姓名")] 
  30.         [FieldDescription(ColumnName="SUR_NAME",FriendlyName="姓名",NeedUpdate=true)] 
  31.         public string Name { get; set; } 
  32.  
  33.         private static readonly PropertyInfo<string> PasswordProperty = RegisterProperty<string>(c => c.Password); 
  34.         [DisplayName("密碼")] 
  35.         [FieldDescription(ColumnName="SUR_PASSWORD",FriendlyName="密碼",NeedUpdate=true)] 
  36.         public string Password { get; set; } 
  37.  
  38.         private static readonly PropertyInfo<string> LoginMacProperty = RegisterProperty<string>(c => c.LoginMac); 
  39.         [DisplayName("登錄Mac地址")] 
  40.         [FieldDescription(ColumnName="SUR_LOGIN_MAC",FriendlyName="登錄Mac地址",NeedUpdate=true)] 
  41.         public string LoginMac { get; set; } 
  42.  
  43.         private static readonly PropertyInfo<string> LoginIPProperty = RegisterProperty<string>(c => c.LoginIP); 
  44.         [DisplayName("登錄IP")] 
  45.         [FieldDescription(ColumnName="SUR_LOGIN_IP",FriendlyName="登錄IP",NeedUpdate=true)] 
  46.         public string LoginIP { get; set; } 
  47.  
  48.  
  49.         private static readonly PropertyInfo<DateTime?> LoginTimeProperty = RegisterProperty<DateTime?>(c => c.LoginTime); 
  50.         [DisplayName("登錄時間")] 
  51.         [FieldDescription(ColumnName="SUR_LOGIN_TIME",FriendlyName="登錄時間",NeedUpdate=true)] 
  52.         public DateTime? LoginTime { get; set; } 
  53.  
  54.         private static readonly PropertyInfo<DateTime?> LogoutTimeProperty = RegisterProperty<DateTime?>(c => c.LogoutTime); 
  55.         [DisplayName("登出時間")] 
  56.         [FieldDescription(ColumnName="SUR_LOGOUT_TIME",FriendlyName="登出時間",NeedUpdate=true)] 
  57.         public DateTime? LogoutTime { get; set; } 
  58.  
  59.         private static readonly PropertyInfo<DateTime?> LoginFailTimeProperty = RegisterProperty<DateTime?>(c => c.LoginFailTime); 
  60.         [DisplayName("登錄失敗時間")] 
  61.         [FieldDescription(ColumnName="SUR_LOGIN_FAIL_TIME",FriendlyName="登錄失敗時間",NeedUpdate=true)] 
  62.         public DateTime? LoginFailTime { get; set; } 
  63.  
  64.         private static readonly PropertyInfo<Int32?> LoginFailCountProperty = RegisterProperty<Int32?>(c => c.LoginFailCount); 
  65.         [DisplayName("登錄失敗次數(shù)")] 
  66.         [FieldDescription(ColumnName="SUR_LOGIN_FAIL_COUNT",FriendlyName="登錄失敗次數(shù)",NeedUpdate=true)] 
  67.         public Int32? LoginFailCount { get; set; } 
  68.  
  69.  
  70.         private static readonly PropertyInfo<bool?> LockFGProperty = RegisterProperty<bool?>(c => c.LockFG); 
  71.         [DisplayName("是否鎖定")] 
  72.         [FieldDescription(ColumnName="SUR_LOCK_FG",FriendlyName="是否鎖定",NeedUpdate=true)] 
  73.         public bool? LockFG { get; set; } 
  74.  
  75.         private static readonly PropertyInfo<bool?> DisableFGProperty = RegisterProperty<bool?>(c => c.DisableFG); 
  76.         [DisplayName("是否有效")] 
  77.         [FieldDescription(ColumnName="SUR_DISABLE_FG",FriendlyName="是否有效",NeedUpdate=true)] 
  78.         public bool? DisableFG { get; set; } 
  79.  
  80.  
  81.         #region 通用字段 
  82.  
  83.         private static readonly PropertyInfo<DateTime?> CreateTimeProperty = RegisterProperty<DateTime?>(c => c.CreateTime); 
  84.         [DisplayName("創(chuàng)建時間")] 
  85.         [FieldDescription(ColumnName="CreateTime",FriendlyName="創(chuàng)建時間",NeedUpdate=true)] 
  86.         public override DateTime? CreateTime { get; set; } 
  87.  
  88.         private static readonly PropertyInfo<DateTime?> LastUpdateTimeProperty = RegisterProperty<DateTime?>(c => c.LastUpdateTime); 
  89.         [DisplayName("***修改時間")] 
  90.         [FieldDescription(ColumnName="LastUpdateTime",FriendlyName="***修改時間",NeedUpdate=true)] 
  91.         public override DateTime? LastUpdateTime { get; set; } 
  92.  
  93.  
  94.  
  95.         public override void SetPrimaryKey(string key
  96.         { 
  97.             SUR_ID = key
  98.         } 
  99.         #endregion 
  100.     } 
  101.  
  102.     [Serializable
  103.     public class SysUserList : IfBusinessList<SysUserList, SysUser> 
  104.     { } 

現(xiàn)在就可以工作了:

全表檢索數(shù)據(jù)方法:

  1. SysUserList selData = SysUserList.Fetch(); 

向數(shù)據(jù)庫新增一條數(shù)據(jù):

  1. SysUser.Business.SysUser user = new SysUser.Business.SysUser(); 
  2. user.UserName= "inaction"
  3. user.Name = "流砂"
  4. user.Password"superman"
  5. selData.Add(user); 
  6. selData.Save(); 

向數(shù)據(jù)庫修改數(shù)據(jù):

  1. var user = SysUserList.Fetch(c => c.UserName == "inaction"); 
  2. user.Password = "123456"
  3.  SysUserList list = new SysUserList { user }; 
  4.  list.Save(); 

以上代碼就實現(xiàn)了對密碼的修改。

特別說明:目前IF 只能通過SysUserList對象的Save方法保存數(shù)據(jù)。以后會實現(xiàn)通過業(yè)務類自身Save方法保存數(shù)據(jù)。

原文鏈接:http://www.cnblogs.com/nactioncsla/p/3439820.html

責任編輯:彭凡 來源: 51CTO
相關(guān)推薦

2011-03-03 11:07:57

Spring數(shù)據(jù)庫訪問ORM

2016-09-23 13:34:15

PythonORMsqlalchemy

2011-05-26 15:20:46

Oracle數(shù)據(jù)庫導出

2021-06-10 13:50:55

代碼開發(fā)數(shù)據(jù)庫

2009-09-15 10:02:44

Linq to SQL

2011-03-16 17:26:22

動態(tài)數(shù)據(jù)庫

2010-05-20 14:52:42

MySQL數(shù)據(jù)庫

2009-07-02 09:35:02

hibernate訪問

2025-04-03 08:30:00

Python數(shù)據(jù)庫ORM

2009-12-29 11:15:45

ADO數(shù)據(jù)庫

2018-07-13 09:20:30

SQLite數(shù)據(jù)庫存儲

2023-11-02 08:56:59

ORMGORM

2025-04-10 10:20:12

Web 應用異步數(shù)據(jù)庫FastAPI

2010-04-29 11:53:42

Oracle數(shù)據(jù)庫

2024-01-15 13:34:00

2011-03-03 16:31:33

2011-03-07 17:35:09

JavaACCESS數(shù)據(jù)庫

2011-05-19 11:33:38

數(shù)據(jù)庫訪問速度

2011-04-13 14:07:17

OracleSybase數(shù)據(jù)庫

2010-12-27 16:18:59

本地元數(shù)據(jù)庫
點贊
收藏

51CTO技術(shù)棧公眾號