微型项目实践(6):Business层代码分析——实体类的生成策略2011-11-24 博客园 冬冬上一篇中,我们分析了实体类的基类Entity,这一篇中,我们就分析一下基于该类的实体类。


每一个实体类都会有两个文件组成,我们以BlogClass为例,该类包含两个文件:BlogClass.cs和 BlogClass.designer.cs,这非常类似VS自己生成的代码,更方便的是,VS还会自动把这两个文件折叠起 来,如图。这两个文件中,BlogClass.designer.cs包含所有的生成代码:成员、属性等,而BlogClass.cs则只包 含一个类的定义,供我们填写代码使用。BlogClass.designer.cs的代码如下。
  1: using System;  2: using System.Collections.Generic;  3: using System.Data.Linq;  4: using System.Linq;  5: using System.Text;  6:   7: using DongBlog.Common;  8:   9: namespace DongBlog.Business.Blogs 10: { 11:   /// <summary> 12:   /// 日志分类 13:   /// </summary> 14:   public partial class BlogClass 15:   { 16:     #region ID和时间戳 17:  18:     private int _ID = NEW_ENTITY_ID; 19:     private byte[] _TimeStamp = new byte[] { }; 20:  21:     /// <summary> 22:     /// 取得ID 23:     /// </summary> 24:     public override int ID 25:     { 26:       get { return _ID; } 27:     } 28:     /// <summary> 29:     /// 取得时间戳 30:     /// </summary> 31:     public override byte[] TimeStamp 32:     { 33:       get { return _TimeStamp; } 34:     } 35:  36:     #endregion 37:  38:     #region 成员 39:  40:     private string _Name; 41:     private string _Description; 42:  43:     #endregion 44:  45:     #region 属性 46:  47:     /// <summary> 48:     /// 取得或设置名称 49:     /// </summary> 50:     public string Name 51:     { 52:       get { return _Name; } 53:       set { _Name = value; } 54:     } 55:     /// <summary> 56:     /// 取得或设置描述 57:     /// </summary> 58:     public string Description 59:     { 60:       get { return _Description; } 61:       set { _Description = value; } 62:     } 63:  64:     #endregion 65:   } 66: }