-
Notifications
You must be signed in to change notification settings - Fork 0
/
OracleContext.cs
157 lines (146 loc) · 7.74 KB
/
OracleContext.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
using Dapper;
using Oracle.ManagedDataAccess.Client;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
namespace MicroORM.Oracle
{
public class OracleContext : IDbContext
{
private string connectionString;
/// <summary>
/// SET SQL Database connection string
/// </summary>
/// <param name="connectionString"></param>
public OracleContext(string connectionString)
{
this.connectionString = connectionString;
}
public IEnumerable<T> Query<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.Query<T>(query, data, transaction, true, commandTimeOut, commandType);
}
}
public async Task<IEnumerable<T>> QueryAsync<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.QueryAsync<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public T QueryFirst<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.QueryFirst<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public async Task<T> QueryFirstAsync<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.QueryFirstAsync<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public T QuerySingle<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.QuerySingle<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public async Task<T> QuerySingleAsync<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.QuerySingleAsync<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public T QueryFirstOrDefault<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.QueryFirstOrDefault<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public async Task<T> QueryFirstOrDefaultAsync<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.QueryFirstOrDefaultAsync<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public T QuerySingleOrDefault<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.QuerySingleOrDefault<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public async Task<T> QuerySingleOrDefaultAsync<T>(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.QuerySingleOrDefaultAsync<T>(query, data, transaction, commandTimeOut, commandType);
}
}
public SqlMapper.GridReader QueryMultiple(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.QueryMultiple(query, data, transaction, commandTimeOut, commandType);
}
}
public async Task<SqlMapper.GridReader> QueryMultipleAsync(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.QueryMultipleAsync(query, data, transaction, commandTimeOut, commandType);
}
}
public int Execute(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.Execute(query, data, transaction, commandTimeOut, commandType);
}
}
public async Task<int> ExecuteAsync(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.ExecuteAsync(query, data, transaction, commandTimeOut, commandType);
}
}
public IDataReader ExecuteReader(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.ExecuteReader(query, data, transaction, commandTimeOut, commandType);
}
}
public async Task<IDataReader> ExecuteReaderAsync(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.ExecuteReaderAsync(query, data, transaction, commandTimeOut, commandType);
}
}
public object ExecuteScalar(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return con.ExecuteScalar(query, data, transaction, commandTimeOut, commandType);
}
}
public async Task<object> ExecuteScalarAsync(string query, object data = null, IDbTransaction transaction = null, int? commandTimeOut = null, CommandType? commandType = null)
{
using (OracleConnection con = new OracleConnection(connectionString))
{
return await con.ExecuteScalarAsync(query, data, transaction, commandTimeOut, commandType);
}
}
}
}