Mercurial > pub > bltoolkit
comparison Source/DataAccess/SprocQueryT.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System.Collections.Generic; | |
2 | |
3 using BLToolkit.Data; | |
4 | |
5 namespace BLToolkit.DataAccess | |
6 { | |
7 public class SprocQuery<T> : DataAccessorBase | |
8 { | |
9 #region Constructors | |
10 | |
11 public SprocQuery() | |
12 { | |
13 } | |
14 | |
15 public SprocQuery(DbManager dbManager) | |
16 : base(dbManager) | |
17 { | |
18 } | |
19 | |
20 public SprocQuery(DbManager dbManager, bool dispose) | |
21 : base(dbManager, dispose) | |
22 { | |
23 } | |
24 | |
25 #endregion | |
26 | |
27 #region SelectByKey | |
28 | |
29 public virtual T SelectByKey(DbManager db, params object[] key) | |
30 { | |
31 return db | |
32 .SetSpCommand(GetSpName(typeof(T), "SelectByKey"), key) | |
33 .ExecuteObject<T>(); | |
34 } | |
35 | |
36 public virtual T SelectByKey(params object[] key) | |
37 { | |
38 DbManager db = GetDbManager(); | |
39 | |
40 try | |
41 { | |
42 return SelectByKey(db, key); | |
43 } | |
44 finally | |
45 { | |
46 Dispose(db); | |
47 } | |
48 } | |
49 | |
50 #endregion | |
51 | |
52 #region SelectAll | |
53 | |
54 public virtual List<T> SelectAll(DbManager db) | |
55 { | |
56 return db | |
57 .SetSpCommand(GetSpName(typeof(T), "SelectAll")) | |
58 .ExecuteList<T>(); | |
59 } | |
60 | |
61 public virtual L SelectAll<L>(DbManager db, L list) | |
62 where L : IList<T> | |
63 { | |
64 return db | |
65 .SetSpCommand(GetSpName(typeof(T), "SelectAll")) | |
66 .ExecuteList<L,T>(list); | |
67 } | |
68 | |
69 public virtual L SelectAll<L>(DbManager db) | |
70 where L : IList<T>, new() | |
71 { | |
72 return SelectAll<L>(db, new L()); | |
73 } | |
74 | |
75 public virtual List<T> SelectAll() | |
76 { | |
77 DbManager db = GetDbManager(); | |
78 | |
79 try | |
80 { | |
81 return SelectAll(db); | |
82 } | |
83 finally | |
84 { | |
85 Dispose(db); | |
86 } | |
87 } | |
88 | |
89 public virtual L SelectAll<L>(L list) | |
90 where L : IList<T> | |
91 { | |
92 DbManager db = GetDbManager(); | |
93 | |
94 try | |
95 { | |
96 return SelectAll(db, list); | |
97 } | |
98 finally | |
99 { | |
100 Dispose(db); | |
101 } | |
102 } | |
103 | |
104 public virtual L SelectAll<L>() | |
105 where L : IList<T>, new() | |
106 { | |
107 return SelectAll<L>(new L()); | |
108 } | |
109 | |
110 #endregion | |
111 | |
112 #region Insert | |
113 | |
114 public virtual void Insert(DbManager db, T obj) | |
115 { | |
116 db | |
117 .SetSpCommand( | |
118 GetSpName(obj.GetType(), "Insert"), | |
119 db.CreateParameters(obj)) | |
120 .ExecuteNonQuery(); | |
121 } | |
122 | |
123 public virtual void Insert(T obj) | |
124 { | |
125 var db = GetDbManager(); | |
126 | |
127 try | |
128 { | |
129 Insert(db, obj); | |
130 } | |
131 finally | |
132 { | |
133 Dispose(db); | |
134 } | |
135 } | |
136 | |
137 #endregion | |
138 | |
139 #region Update | |
140 | |
141 public virtual int Update(DbManager db, T obj) | |
142 { | |
143 return db | |
144 .SetSpCommand( | |
145 GetSpName(obj.GetType(), "Update"), | |
146 db.CreateParameters(obj)) | |
147 .ExecuteNonQuery(); | |
148 } | |
149 | |
150 public virtual int Update(T obj) | |
151 { | |
152 DbManager db = GetDbManager(); | |
153 | |
154 try | |
155 { | |
156 return Update(db, obj); | |
157 } | |
158 finally | |
159 { | |
160 Dispose(db); | |
161 } | |
162 } | |
163 | |
164 #endregion | |
165 | |
166 #region DeleteByKey | |
167 | |
168 public virtual int DeleteByKey(DbManager db, params object[] key) | |
169 { | |
170 return db | |
171 .SetSpCommand(GetSpName(typeof(T), "Delete"), key) | |
172 .ExecuteNonQuery(); | |
173 } | |
174 | |
175 public virtual int DeleteByKey(params object[] key) | |
176 { | |
177 DbManager db = GetDbManager(); | |
178 | |
179 try | |
180 { | |
181 return DeleteByKey(db, key); | |
182 } | |
183 finally | |
184 { | |
185 Dispose(db); | |
186 } | |
187 } | |
188 | |
189 #endregion | |
190 | |
191 #region Delete | |
192 | |
193 public virtual int Delete(DbManager db, T obj) | |
194 { | |
195 return db | |
196 .SetSpCommand( | |
197 GetSpName(obj.GetType(), "Delete"), | |
198 db.CreateParameters(obj)) | |
199 .ExecuteNonQuery(); | |
200 } | |
201 | |
202 public virtual int Delete(T obj) | |
203 { | |
204 DbManager db = GetDbManager(); | |
205 | |
206 try | |
207 { | |
208 return Delete(db, obj); | |
209 } | |
210 finally | |
211 { | |
212 Dispose(db); | |
213 } | |
214 } | |
215 | |
216 #endregion | |
217 } | |
218 } |