C 輕量級ORM 編寫思維

2022-02-04 14:01:48 字數 4298 閱讀 9454

目標:

降低研發人員門檻,提高效率,去除重複引用dll的工作,基礎配置由抽象工廠處理。

基礎擴充套件

/// /// datatable 轉換為list 集合

///

/// 型別

/// datatable

///

public static listtolist(this datatable dt) where tresult : class,new()

/// /// 轉換為乙個datatable

///

///

///

///

public static datatable todatatable(this ienumerablevalue) where tresult : class

業務邏輯介面

//name:wujc 2013-06-20

namespace yc.bll

#region 成員方法

/// /// 獲取錶行數

///

///

///

///

public int getrowscount(string strwhere) where t : basemodel, new()

/// /// 獲取錶行數

///

///

///

///

public int getrowscount(string sql)

/// /// 是否存在該記錄

///

public bool exists(string id) where t : basemodel, new()

/// /// 增加一條資料

///

public bool add(t model) where t : basemodel, new()

/// /// 增加多條資料

///

///

///

///

public bool add(listmodellist) where t : basemodel, new()

/// /// 更新一條資料

///

public bool update(t model) where t : basemodel, new()

/// /// 更新多條資料

///

///

///

///

public bool update(listmodellist) where t : basemodel, new()

/// /// 刪除一條資料

///

public bool delete(string id) where t : basemodel, new()

/// /// 刪除一條資料

///

///

///

///

public bool delete(t model) where t : basemodel, new()

/// /// 刪除多條資料

///

///

///

///

public bool delete(listmodellist) where t : basemodel, new()

/// /// 批量刪除資料

///

/// 逗號分隔

///

public bool deletelist(string idlist) where t : basemodel, new()

/// /// 得到乙個物件實體

///

public t getmodel(string id) where t : basemodel, new()

/// /// 得到全部物件實體

///

public listgetmodellist(string strwhere) where t : basemodel, new()

/// /// 獲得資料列表

///

public dataset getlist(string strwhere) where t : basemodel, new()

/// /// 獲得資料表

///

public datatable gettable(string strwhere) where t : basemodel, new()

/// /// 根據分頁獲得資料列表

///

public dataset getlist(string strwhere, string orderby, int startindex, int endindex) where t : basemodel, new()

/// /// 根據分頁獲得資料列表

///

public dataset getlistbysql(string sql, string orderby, int startindex, int endindex)

/// /// 執行sql語句,返回影響的記錄數

///

/// sql語句

/// 影響的記錄數

public int executesql(string sqlstring)

/// /// 執行查詢語句,返回dataset

///

/// 查詢語句

/// dataset

public dataset query(string sqlstring)

/// /// 執行多條sql語句,實現資料庫事務。

///

/// sql語句的雜湊表(key為sql語句,value是該語句的sqlparameter)

public void executesqltran(hashtable sqlstringlist)

#endregion 成員方法

因為這還是個公司框架,還不能開源,不過看完以上介面定義之後,已經知道個大概了吧。

資料邏輯抽象工廠,由抽象介面層,根據配置建立抽象例項,還有緩衝池等。

資料邏輯基礎方法和介面

這些很基礎的,網上也一大把,我只是為了配合框架做了一些小修改。

接著,每創立乙個新專案,都不需要重新再去重做一套orm 了, 引入以上所說的。

接著,新增乙個model層,值得主意的是,model要繼承yc.base的basemodel。

示例:

/// /// 使用者表

///

[system.serializable()]

public class userinfo : yc.base.basemodel

private system.string _userinfoid;

/// /// 使用者id,nvarchar2,128

///

public system.string userinfoid

set}

private system.string _name;

/// /// 使用者名稱,nvarchar2,500

///

public system.string name

set}

private system.string _pwd;

/// /// 使用者密碼,nvarchar2,500

再引用你該項目的model層

一切就這樣簡單,希望對大家了解orm有所幫助!

by:五加乘

peewee 超輕量級ORM運算元據庫

多條刪除,返回值為刪除的條數 1 delete instance tusermission.delete where tusermission.mission code mission code execute 單條刪除 2 name tusermission.get user name zhang...

peewee 乙個輕量級的ORM 四

class database last insert id cursor,model parameters return type 最後乙個插入的記錄的那行的主鍵,不一定非得叫 id rows affected cursor return type 受影響的行數 create table model...

原創的輕量級ORM,支援Lambda進行資料庫操作

這個orm已經用了好幾個月了基本完善了,現在來分享下他的操作方式 db.instance.insert message add o o.product,msg.product add o o.email,msg.email add o o.phone,msg.phone add o o.addres...