-
Notifications
You must be signed in to change notification settings - Fork 8
/
IRepositoryGeneric.cs
364 lines (324 loc) · 21.2 KB
/
IRepositoryGeneric.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Dapper.SimpleRepository
{
/// <summary>
/// Create a generic (weakly) typed instance of Dapper.SimpleRepository.
/// </summary>
public interface IRepositoryGeneric
{
/// <summary>
/// <para>Get a specific record by the primary key (id).</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <param name="id"></param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single record of type T where the primary key matches the supplied id.</returns>
T Get<T>(object id, int? commandTimeout = null);
/// <summary>
/// <para>Get a specific record by the primary key (id).</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <param name="id"></param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single record of type T where the primary key matches the supplied id.</returns>
Task<T> GetAsync<T>(object id, int? commandTimeout = null);
/// <summary>
/// <para>Get a specific record that matches the specified filter.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="where">The SQL WHERE clause.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single record of type T where the data matches the supplied WHERE filter.</returns>
T Get<T>(string where, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Get a specific record that matches the specified filter</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="where">The SQL WHERE clause.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single record of type T where the data matches the supplied WHERE filter.</returns>
Task<T> GetAsync<T>(string where, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Get a specific type from a query. This type could be a database model, or it could be a single string, or it could be an INT if the query is a SELECT COUNT().</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="query"></param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single instance of type T that matches the supplied query.</returns>
T GetFromQuery<T>(string query, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Get a specific type from a query. This type could be a database model, or it could be a single string, or it could be an INT if the query is a SELECT COUNT().</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="query"></param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single instance of type T that matches the supplied query.</returns>
Task<T> GetFromQueryAsync<T>(string query, Dictionary<string, object> parms = null, int? commandTimeout = null);
// ----------- GET List Methods ----------- //
/// <summary>
/// <para>Get an IEnumerable of all records.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <returns>an IEnumerable of type T.</returns>
IEnumerable<T> GetAll<T>();
/// <summary>
/// <para>Get an IEnumerable of all records.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <returns>An IEnumerable of type T.</returns>
Task<IEnumerable<T>> GetAllAsync<T>();
/// <summary>
/// <para>Get an IEnumerable that matches the specified filter</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="where">The SQL WHERE clause.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>An IEnumerable of type T where the data matches the supplied WHERE filter.</returns>
IEnumerable<T> GetList<T>(string where, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Get an IEnumerable that matches the specified filter</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="where">The SQL WHERE clause.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>An IEnumerable of type T where the data matches the supplied WHERE filter.</returns>
Task<IEnumerable<T>> GetListAsync<T>(string where, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Get an IEnumerable based on a custom query and any (optional) parameters</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="query"></param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>An IEnumerable of type T that matches the supplied query.</returns>
IEnumerable<T> GetListFromQuery<T>(string query, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Get an IEnumerable based on a custom query and any (optional) parameters</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="query"></param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>An IEnumerable of type T that matches the supplied query.</returns>
Task<IEnumerable<T>> GetListFromQueryAsync<T>(string query, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Get a paged IEnumerable of all records.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="pageNumber">The offset (or page number) of the total set to select.</param>
/// <param name="rowsPerPage">The number of total records to return per page.</param>
/// <param name="where">Optional WHERE clause to filter the resutls.</param>
/// <param name="orderBy">Optional ORDER BY clause to order the results.</param>
/// <param name="parms">Optinal set of paramaters used in WHERE or ORDER BY clauses.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A paged IEnumerable of type T.</returns>
IEnumerable<T> GetListPaged<T>(int pageNumber, int rowsPerPage, string where, string orderBy, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Get a paged IEnumerable of all records.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="pageNumber">The offset (or page number) of the total set to select.</param>
/// <param name="rowsPerPage">The number of total records to return per page.</param>
/// <param name="where">Optional WHERE clause to filter the resutls.</param>
/// <param name="orderBy">Optional ORDER BY clause to order the results.</param>
/// <param name="parms">Optinal set of paramaters used in WHERE or ORDER BY clauses.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A paged IEnumerable of type T.</returns>
Task<IEnumerable<T>> GetListPagedAsync<T>(int pageNumber, int rowsPerPage, string where, string orderBy, Dictionary<string, object> parms = null, int? commandTimeout = null);
// ----------- UPDATE Methods ----------- //
/// <summary>
/// <para>Update an existing record.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <param name="entity">An instance of type T to be updated.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>Number of rows affected.</returns>
int Update<T>(T entity, int? commandTimeout = null);
/// <summary>
/// <para>Update an existing record.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <param name="entity">An instance of type T to be updated.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>Number of rows affected.</returns>
Task<int> UpdateAsync<T>(T entity, int? commandTimeout = null);
// ----------- INSERT Methods ----------- //
/// <summary>
/// <para>Insert a new record.</para>
/// <para>Inserts into the table matching the type T.</para>
/// </summary>
/// <param name="entity">An instance of type T to be updated.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>The ID (primary key) of the newly inserted record.</returns>
int? Insert<T>(T entity, int? commandTimeout = null);
/// <summary>
/// <para>Insert a new record.</para>
/// <para>Inserts into the table matching the type T.</para>
/// <para>Allows the PK Type to be defined.</para>
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="T"></typeparam>
/// <param name="entity"></param>
/// <param name="commandTimeout"></param>
/// <returns></returns>
TKey Insert<TKey, T>(T entity, int? commandTimeout = null);
/// <summary>
/// <para>Insert a new record.</para>
/// <para>Inserts into the table matching the type T.</para>
/// </summary>
/// <param name="entity">An instance of type T to be updated.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>The ID (primary key) of the newly inserted record.</returns>
Task<int?> InsertAsync<T>(T entity, int? commandTimeout = null);
/// <summary>
/// <para>Insert a new record.</para>
/// <para>Inserts into the table matching the type T.</para>
/// <para>Allows the PK Type to be defined.</para>
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="T"></typeparam>
/// <param name="entity"></param>
/// <param name="commandTimeout"></param>
/// <returns></returns>
Task<TKey> InsertAsync<TKey, T>(T entity, int? commandTimeout = null);
// ----------- DELETE Methods ----------- //
/// <summary>
/// <para>Delete a record by primary key (id).</para>
/// <para>Deletes from the table matching the type T.</para>
/// </summary>
/// <param name="id">The ID (primary key) of the item to be deleted.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>Number of rows affected.</returns>
int Delete<T>(object id, int? commandTimeout = null);
/// <summary>
/// <para>Delete a record by primary key (id).</para>
/// <para>Deletes from the table matching the type T.</para>
/// </summary>
/// <param name="id">The ID (primary key) of the item to be deleted.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>Number of rows affected.</returns>
Task<int> DeleteAsync<T>(object id, int? commandTimeout = null);
/// <summary>
/// <para>Delete all records that match the specified filter.</para>
/// <para>Deletes from the table matching the type T.</para>
/// </summary>
/// <param name="where">Optional WHERE clause.</param>
/// <param name="parms">Optional set of parameters that matches the WHERE clause.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>Number of rows affected.</returns>
int Delete<T>(string where, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Delete all records that match the specified filter.</para>
/// <para>Deletes from the table matching the type T.</para>
/// </summary>
/// <param name="where">Optional WHERE clause.</param>
/// <param name="parms">Optional set of parameters that matches the WHERE clause.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>Number of rows affected.</returns>
Task<int> DeleteAsync<T>(string where, Dictionary<string, object> parms = null, int? commandTimeout = null);
// ----------- EXECUTE QUERY Method ----------- //
/// <summary>
/// <para>Execute any custom query where a return data set it not expected.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="query">Full SQL query.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
void ExecuteQuery<T>(string query, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Execute any custom query where a return data set it not expected.</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="query">Full SQL query.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
Task ExecuteQueryAsync<T>(string query, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Execute any custom query where a single return item is expected. This type could be a database model, or it could be a single string, or it could be an INT if the query is a SELECT COUNT().</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <param name="query">Full SQL query.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single instance of type T that matches the supplied query.</returns>
T ExecuteScalar<T>(string query, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Execute any custom query where a single return item is expected. This type could be a database model, or it could be a single string, or it could be an INT if the query is a SELECT COUNT().</para>
/// <para>Queries the table matching the type T.</para>
/// </summary>
/// <param name="query">Full SQL query.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single instance of type T that matches the supplied query.</returns>
Task<T> ExecuteScalarAsync<T>(string query, Dictionary<string, object> parms = null, int? commandTimeout = null);
// ----------- STORED PROCEDURE Methods ----------- //
/// <summary>
/// <para>Execute any Stored Procedure where a return data set it not expected.</para>
/// </summary>
/// <param name="storedProcedureName">Name of the stored procedure to be executed.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
void ExecuteSP(string storedProcedureName, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Execute any Stored Procedure where a return data set it not expected.</para>
/// </summary>
/// <param name="storedProcedureName">Name of the stored procedure to be executed.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
Task ExecuteSPAsync(string storedProcedureName, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Execute any Stored Procedure where a single item is expected as a return.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="storedProcedureName">Name of the stored procedure to be executed.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single instance of type T.</returns>
T ExecuteSPSingle<T>(string storedProcedureName, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Execute any Stored Procedure where a single item is expected as a return.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="storedProcedureName">Name of the stored procedure to be executed.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>A single instance of type T.</returns>
Task<T> ExecuteSPSingleAsync<T>(string storedProcedureName, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Execute a Store Procedure when a List of T is expected in return.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="storedProcedureName">Name of the stored procedure to be executed.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>An IEnumerable of type T.</returns>
IEnumerable<T> ExecuteSPList<T>(string storedProcedureName, Dictionary<string, object> parms = null, int? commandTimeout = null);
/// <summary>
/// <para>Execute a Store Procedure when a List of T is expected in return.</para>
/// </summary>
/// <typeparam name="T">The type that matches the database table.</typeparam>
/// <param name="storedProcedureName">Name of the stored procedure to be executed.</param>
/// <param name="parms">Optional set of parameters that matches the query.</param>
/// <param name="commandTimeout">Optional command time out value.</param>
/// <returns>An IEnumerable of type T.</returns>
Task<IEnumerable<T>> ExecuteSPListAsync<T>(string storedProcedureName, Dictionary<string, object> parms = null, int? commandTimeout = null);
}
}