日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

SqlHelper简单实现(通过Expression和反射)2.特性和实体设计

發布時間:2025/4/9 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SqlHelper简单实现(通过Expression和反射)2.特性和实体设计 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

對于需求中的不要暴露DataTable或DataSet,我想到了設計中常用的對象:實體(Entity),通過實體將數據庫中的字段封裝成類,這樣做不僅使代碼更有可讀性,維護起來也很方便。同時我自定義了一些C#特性來表述字段在數據庫中的特性。

1.遞增鍵:

1 namespace RA.DataAccess.Attributes 2 { 3 /// <summary> 4 /// 遞增鍵 5 /// </summary> 6 [AttributeUsage(AttributeTargets.Property, Inherited = true)] 7 public class IdentityAttribute:Attribute 8 { 9 } 10 }

2.主鍵:

1 namespace RA.DataAccess.Attributes 2 { 3 /// <summary> 4 /// 主鍵 5 /// </summary> 6 [AttributeUsage(AttributeTargets.Property, Inherited = true)] 7 public class PrimaryAttribute : Attribute 8 { 9 10 } 11 }

3.表名:

1 namespace RA.DataAccess.Attributes 2 { 3 /// <summary> 4 /// 表名 5 /// </summary> 6 [AttributeUsage(AttributeTargets.Class, Inherited = true)] 7 public class TableNameAttribute : Attribute 8 { 9 public string TableName { get; set; } 10 11 public TableNameAttribute(string name) 12 { 13 TableName = name; 14 } 15 } 16 }

?測試用例:

1 namespace RA.MyBlog.Entity 2 { 3 4 [TableName("RA_MyBlog_Article")] 5 public class ArticleEntity 6 { 7 [Primary] 8 [Identity] 9 //文章ID 10 public int articleID { get; set; } 11 //分類ID 12 public int categoryID { get; set; } 13 //文章標題 14 public string articleTitle { get; set; } 15 //文章版權 16 public string articleCopyright { get; set; } 17 //文章創建時間 18 public DateTime articleDate { get; set; } 19 //文章摘要 20 public string articleAbstract { get; set; } 21 //文章內容 22 public string articleContain { get; set; } 23 //文章所屬User 24 public int userID { get; set; } 25 } 26 }

?

轉載于:https://www.cnblogs.com/kakura/p/6108858.html

總結

以上是生活随笔為你收集整理的SqlHelper简单实现(通过Expression和反射)2.特性和实体设计的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。