一个简单的ibatis.net架构(包含项目模板代码下载)
http://www.cnblogs.com/ctp0925/archive/2008/12/03/1347154.html
1 基本介绍
iBATISNet Database Layer!这个框架将让你能够更好的在dotnet应用中设计和实现实体层。这个框架有两个主要的组成部分,一个是SQL Maps,另一个是Data Access Objects。下面是一个简单的iBATISNet应用架构。
2 架构预览
项目中总共10个项目
External_bin 需要引用的dll
MyCompany.Controls 项目中用到的自定义控件
MyCompany.IbatisNet项目中IbatisNet组件
MyCompany.MyProject.Domain 项目对象
MyCompany.MyProject.Persistence 数据库持久化对象
MyCompany.MyProject.Run 项目运行对象
MyCompany.MyProject.Service 业务服务对象
MyCompany.MyProject.UserControls 界面用户控件对象
MyCompany.MyProject.WinFrom 界面对象
MyCompany.Utility 项目中用到的工具集
3 实体对象层
MyCompany.MyProject.Domain
Entity1.cs源代码
1 /* =====================================================
2 作 者 : 陈励
3 创建时间 : 2008-11-16 22:10:01
4 修 改 者 :
5 修改时间 :
6 描 述 : Entity_1
7 ===================================================== */
8
9 using System;
10 using System.Collections.Generic;
11 using System.Text;
12
13 namespace MyCompany.MyProject.Domain
14 {
15 /// <summary>
16 /// 针对 Entity_1 为IBatisNet创建的类型.
17 /// </summary>
18 [Serializable]
19 public sealed class Entity1
20 {
21 #region 私有变量
22 private bool _isChanged;
23 private bool _isDeleted;
24 private string _attribute1old; // Attribute_1
25 private string _attribute1; // Attribute_1
26 private string _attribute2; // Attribute_2
27 private string _attribute3; // Attribute_3
28 private IList<Entity2> _entity2; // Entity_1
29 #endregion
30
31 #region 构造函数
32 /// <summary>
33 /// 构造函数
34 /// </summary>
35 public Entity1()
36 {
37
38 }
39
40 /// <summary>
41 /// 构造函数
42 /// </summary>
43 /// <param name="attribute1">Attribute_1</param>
44 /// <param name="attribute2">Attribute_2</param>
45 /// <param name="attribute3">Attribute_3</param>
46 public Entity1(string attribute1, string attribute2, string attribute3)
47 {
48 this.Attribute1 = attribute1;
49 this.Attribute2 = attribute2;
50 this.Attribute3 = attribute3;
51 }
52
53 #endregion
54
55 #region 公共属性
56
57 /// <summary>
58 /// Attribute_1
59 /// </summary>
60 public string Attribute1Old
61 {
62 get
63 {
64 return _attribute1old;
65 }
66 set
67 {
68 _attribute1old = value;
69 }
70 }
71
72 /// <summary>
73 /// Attribute_1
74 /// </summary>
75 public string Attribute1
76 {
77 get
78 {
79 return _attribute1;
80 }
81 set
82 {
83 if (value != null && Encoding.Default.GetByteCount(value.ToString()) > 50)
84 throw new ArgumentOutOfRangeException("Attribute1", value.ToString(), "Attribute_1_长度超出限制(50)!");
85
86 _isChanged |= (_attribute1 != value);
87 _attribute1 = value;
88 if (_attribute1old == null)
89 _attribute1old = _attribute1;
90 }
91 }
92
93 /// <summary>
94 /// Attribute_2
95 /// </summary>
96 public string Attribute2
97 {
98 get
99 {
100 return _attribute2;
101 }
102 set
103 {
104 if (value != null && Encoding.Default.GetByteCount(value.ToString()) > 50)
105 throw new ArgumentOutOfRangeException("Attribute2", value.ToString(), "Attribute_2_长度超出限制(50)!");
106
107 _isChanged |= (_attribute2 != value);
108 _attribute2 = value;
109 }
110 }
111
112 /// <summary>
113 /// Attribute_3
114 /// </summary>
115 public string Attribute3
116 {
117 get
118 {
119 return _attribute3;
120 }
121 set
122 {
123 if (value != null && Encoding.Default.GetByteCount(value.ToString()) > 50)
124 throw new ArgumentOutOfRangeException("Attribute3", value.ToString(), "Attribute_3_长度超出限制(50)!");
125
126 _isChanged |= (_attribute3 != value);
127 _attribute3 = value;
128 }
129 }
130
131 /// <summary>
132 /// Entity_1
133 /// </summary>
134 public IList<Entity2> Entity2
135 {
136 get
137 {
138 return _entity2;
139 }
140 set
141 {
142 if (value != null)
143 {
144 foreach (Entity2 prt in value)
145 {
146 prt.Entity1 = this;
147 }
148 }
149 _isChanged |= (_entity2 != value); _entity2 = value;
150 }
151 }
152
153 /// <summary>
154 /// 表示实例是否已经发生改变.
155 /// </summary>
156 public bool IsChanged
157 {
158 get { return _isChanged; }
159 }
160
161 /// <summary>
162 /// 表示实例是否已经被删除.
163 /// </summary>
164 public bool IsDeleted
165 {
166 get { return _isDeleted; }
167 }
168
169 #endregion
170
171 #region 公共方法
172
173 /// <summary>
174 /// 调用方法,标识实例已经被删除.
175 /// </summary>
176 public void MarkAsDeleted()
177 {
178 _isDeleted = true;
179 _isChanged = true;
180 }
181 /// <summary>
182 /// 清空状态,设置为未改动.
183 /// </summary>
184 public void ClearMarks()
185 {
186 _isDeleted = false;
187 _isChanged = false;
188 }
189
190 /// <summary>
191 /// 设置已改动.
192 /// </summary>
193 public void Changed()
194 {
195 _isChanged = true;
196 }
197
198 #endregion
199
200 }
201 }
202
4 数据层
MyCompany.MyProject.Persistence
Interfaces 数据层接口
IEntity1Dao.cs 源代码
Code
MapperDao 数据层操作对象
Entity1SqlMapDao.cs源代码
Code