編寫自己的dapper lambda擴充套件 使用篇

2022-02-12 07:18:03 字數 2739 閱讀 9530

去年寫了《整理自己的.net工具庫》,裡面提供的原始碼重新發布到了github並用新的專案名sikiro.tookits

這兩個專案都發布到nuget上了,可以在nuget搜尋sikiro可以全部檢視到

另外該專案會用到一些表示式樹的知識,如果有興趣的朋友可以先去了解,我之前也寫過一篇簡單的文章《表示式樹的解析.》

下面是簡單的使用介紹

var con = new sqlconnection("data source=192.168.13.46;initial catalog=skychen;persist security info=true;user id=sa;password=123456789");
[table("sys_user")]

public class sysuser

/// /// 建立時間

///

[required]

[display(name = "建立時間")]

[column("create_datetime")]

public datetime createdatetime

/// /// 郵箱

///

[required]

[stringlength(32)]

[display(name = "郵箱")]

[column("email")]

public string email

/// /// user_status

///

[required]

[display(name = "user_status")]

[column("user_status")]

public int userstatus

}

con.commandset().insert(new sysuser

);

當不存在某條件記錄insert

con.commandset().ifnotexists(a => a.email == "[email protected]").insert(new sysuser

);

您可以根據某個條件把指定字段更新

con.commandset().where(a => a.email == "[email protected]").update(a => new sysuser );
也可以根據主鍵來更新整個實體字段資訊

user.email = "[email protected]";

condb.commandset().update(user);

您可以根據條件來刪除資料

con.commandset().where(a => a.email == "[email protected]").delete()
get

獲取過濾條件的一條資料(第一條)

con.queryset().where(a => a.email == "[email protected]").get()
tolist

當然我們也可以查詢出符合條件的資料集

con.queryset().where(a => a.email == "[email protected]").orderby(b => b.email).top(10).select(a => a.email).tolist();
還有分頁

con.queryset().where(a => a.email == "[email protected]")

.orderby(a => a.createdatetime)

.select(a => new sysuser )

.pagelist(1, 10);

先更新再把結果查詢出來

con.queryset().where(a => a.email == "[email protected]")

.orderby(a => a.createdatetime)

.select(a => new sysuser )

.updateselect(a => new sysuser );

con.transaction(tc =>

);});

using (var con = new sqlconnection("data source=192.168.13.46;initial catalog=skychen;persist security info=true;user id=sa;password=123456789"))

); var model = con.queryset().where(a => a.email == "[email protected]").get();

con.commandset().where(a => a.sysuserid == model.sysuserid)

.update(a => new sysuser );

con.commandset().where(a => a.sysuserid == model.sysuserid).delete();

}

除了簡單的curd還有count、sum、exists

編寫自己的TRACE

在編寫mfc程式時我們經常用trace輸出除錯資訊幫助除錯,但使用trace的前提條件必須是定義了 debug並且使用debug庫才行。有時候在寫某些外掛程式的時候,由於廠商只提供release版本的介面,於是只能把自己的工程中去掉 debug並還用非debug庫,雖然還屬於debug版,但 tra...

自己編寫的linux ls命令

include include include include include include include include include include int aflag 0 int lflag 0 typedef char datatype typedef struct node link...

自己編寫的more命令

重定向方面存在缺憾 重定向後沒有除錯完成 stdin時非重定向可用read和write遮蔽部分部分 include include include include include lstat include lstat include define pagelen 24 define linelen...