-
Notifications
You must be signed in to change notification settings - Fork 43
/
IStoredProcBuilder.cs
144 lines (127 loc) · 7.31 KB
/
IStoredProcBuilder.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
using System;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
namespace StoredProcedureEFCore
{
/// <summary>
/// Stored procedure builder.
/// </summary>
public interface IStoredProcBuilder : IDisposable
{
/// <summary>
/// Add input parameter.
/// </summary>
/// <typeparam name="T">Type of the parameter. Can be nullable.</typeparam>
/// <param name="name">Name of the parameter.</param>
/// <param name="val">Value of the parameter.</param>
IStoredProcBuilder AddParam<T>(string name, T val);
/// <summary>
/// Add input/output parameter.
/// </summary>
/// <typeparam name="T">Type of the parameter. Can be nullable.</typeparam>
/// <param name="name">Name of the parameter.</param>
/// <param name="val">Value of the parameter.</param>
/// <param name="outParam">Created parameter. Value will be populated after calling <see cref="Exec(Action{DbDataReader})"/>.</param>
IStoredProcBuilder AddParam<T>(string name, T val, out IOutParam<T> outParam);
/// <summary>
/// Add input/output parameter.
/// </summary>
/// <typeparam name="T">Type of the parameter. Can be nullable.</typeparam>
/// <param name="name">Name of the parameter.</param>
/// <param name="val">Value of the parameter.</param>
/// <param name="outParam">Created parameter. Value will be populated after calling <see cref="Exec(Action{DbDataReader})"/>.</param>
/// <param name="size">Number of decimal places to which <see cref="IOutParam{T}.Value"/> is resolved.</param>
/// <param name="precision">Number of digits used to represent the <see cref="IOutParam{T}.Value"/> property.</param>
/// <param name="scale">Maximum size, in bytes, of the data within the column.</param>
IStoredProcBuilder AddParam<T>(string name, T val, out IOutParam<T> outParam, int size = 0, byte precision = 0, byte scale = 0);
/// <summary>
/// Add output parameter.
/// </summary>
/// <typeparam name="T">Type of the parameter. Can be nullable.</typeparam>
/// <param name="name">Name of the parameter.</param>
/// <param name="outParam">Created parameter. Value will be populated after calling <see cref="Exec(Action{DbDataReader})"/>.</param>
IStoredProcBuilder AddParam<T>(string name, out IOutParam<T> outParam);
/// <summary>
/// Add output parameter.
/// </summary>
/// <typeparam name="T">Type of the parameter. Can be nullable.</typeparam>
/// <param name="name">Name of the parameter.</param>
/// <param name="outParam">Created parameter. Value will be populated after calling <see cref="Exec(Action{DbDataReader})"/>.</param>
/// <param name="size">Number of decimal places to which <see cref="IOutParam{T}.Value"/> is resolved.</param>
/// <param name="precision">Number of digits used to represent the <see cref="IOutParam{T}.Value"/> property.</param>
/// <param name="scale">Maximum size, in bytes, of the data within the column.</param>
IStoredProcBuilder AddParam<T>(string name, out IOutParam<T> outParam, int size = 0, byte precision = 0, byte scale = 0);
/// <summary>
/// Add pre configured DB query execution parameter directly command.
/// </summary>
/// <param name="parameter">DB query execution parameter <see cref="DbParameter"/>.</param>
IStoredProcBuilder AddParam(DbParameter parameter);
/// <summary>
/// Add return value parameter.
/// </summary>
/// <typeparam name="T">Type of the parameter. Can be nullable.</typeparam>
/// <param name="retParam">Created parameter. Value will be populated after calling <see cref="Exec(Action{DbDataReader})"/>.</param>
IStoredProcBuilder ReturnValue<T>(out IOutParam<T> retParam);
/// <summary>
/// Set the wait time before terminating the attempt to execute the stored procedure and generating an error.
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
IStoredProcBuilder SetTimeout(int timeout);
/// <summary>
/// Execute the stored procedure.
/// </summary>
/// <param name="action">Actions to do with the result sets.</param>
void Exec(Action<DbDataReader> action);
/// <summary>
/// Execute the stored procedure
/// </summary>
/// <param name="action">Actions to do with the result sets.</param>
Task ExecAsync(Func<DbDataReader, Task> action);
/// <summary>
/// Execute the stored procedure.
/// </summary>
/// <param name="action">Actions to do with the result sets.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="TaskCanceledException">When <paramref name="cancellationToken"/> was cancelled.</exception>
Task ExecAsync(Func<DbDataReader, Task> action, CancellationToken cancellationToken);
/// <summary>
/// Execute the stored procedure.
/// </summary>
/// <returns>The number of rows affected.</returns>
int ExecNonQuery();
/// <summary>
/// Execute the stored procedure.
/// </summary>
/// <returns>The number of rows affected.</returns>
Task<int> ExecNonQueryAsync();
/// <summary>
/// Execute the stored procedure.
/// </summary>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="TaskCanceledException">When <paramref name="cancellationToken"/> was cancelled.</exception>
/// <returns>The number of rows affected.</returns>
Task<int> ExecNonQueryAsync(CancellationToken cancellationToken);
/// <summary>
/// Execute the stored procedure and return the first column of the first row.
/// </summary>
/// <typeparam name="T">Type of the scalar value.</typeparam>
/// <param name="val">The first column of the first row in the result set.</param>
void ExecScalar<T>(out T val);
/// <summary>
/// Execute the stored procedure and return the first column of the first row.
/// </summary>
/// <typeparam name="T">Type of the scalar value.</typeparam>
/// <param name="action">Action applied to the first column of the first row in the result set.</param>
Task ExecScalarAsync<T>(Action<T> action);
/// <summary>
/// Execute the stored procedure and return the first column of the first row.
/// </summary>
/// <typeparam name="T">Type of the scalar value.</typeparam>.
/// <param name="action">Action applied to the first column of the first row in the result set.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="TaskCanceledException">When <paramref name="cancellationToken"/> was cancelled.</exception>
Task ExecScalarAsync<T>(Action<T> action, CancellationToken cancellationToken);
}
}