This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConnectionExtensions.cs
131 lines (107 loc) · 5.27 KB
/
ConnectionExtensions.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
using Postulate.Lite.Core.Interfaces;
using System;
using System.Data;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace Postulate.Lite.SqlServer.IntKey
{
public static class ConnectionExtensions
{
private static SqlServerProvider<int> GetProvider()
{
return new SqlServerProvider<int>((obj) => Convert.ToInt32(obj), "identity(1,1)");
}
public static bool Exists<TModel>(this IDbConnection connection, int id, IUser user = null, string tableName = null)
{
return GetProvider().Exists<TModel>(connection, id, user, tableName);
}
public async static Task<bool> ExistsAsync<TModel>(this IDbConnection connection, int id, IUser user = null, string tableName = null)
{
return await GetProvider().ExistsAsync<TModel>(connection, id, user, tableName);
}
public static bool ExistsWhere<TModel>(this IDbConnection connection, object criteria, IUser user = null, string tableName = null)
{
return GetProvider().ExistsWhere<TModel>(connection, criteria, user, tableName);
}
public async static Task<bool> ExistsWhereAsync<TModel>(this IDbConnection connection, object criteria, IUser user = null, string tableName = null)
{
return await GetProvider().ExistsWhereAsync<TModel>(connection, criteria, user, tableName);
}
public static TModel Find<TModel>(this IDbConnection connection, int id, IUser user = null, string tableName = null)
{
return GetProvider().Find<TModel>(connection, id, user, tableName);
}
public async static Task<TModel> FindAsync<TModel>(this IDbConnection connection, int id, IUser user = null, string tableName = null)
{
return await GetProvider().FindAsync<TModel>(connection, id, user, tableName);
}
public static TModel FindWhere<TModel>(this IDbConnection connection, object criteria, IUser user = null, string tableName = null)
{
return GetProvider().FindWhere<TModel>(connection, criteria, user, tableName);
}
public async static Task<TModel> FindWhereAsync<TModel>(this IDbConnection connection, object criteria, IUser user = null, string tableName = null)
{
return await GetProvider().FindWhereAsync<TModel>(connection, criteria, user, tableName);
}
public static int Merge<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
return GetProvider().Merge(connection, @object, user, tableName);
}
public async static Task<int> MergeAsync<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
return await GetProvider().MergeAsync(connection, @object, user, tableName);
}
public static int Save<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
return GetProvider().Save(connection, @object, user, tableName);
}
public async static Task<int> SaveAsync<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
return await GetProvider().SaveAsync(connection, @object, user, tableName);
}
public static int Insert<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
return GetProvider().Insert(connection, @object, user, tableName);
}
public static void PlainInsert<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
GetProvider().PlainInsert(connection, @object, user, tableName);
}
public static async Task PlainInsertAsync<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
await GetProvider().PlainInsertAsync(connection, @object, user, tableName);
}
public async static Task<int> InsertAsync<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
return await GetProvider().InsertAsync(connection, @object, user, tableName);
}
public static void Update<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
GetProvider().Update(connection, @object, user, tableName);
}
public async static Task UpdateAsync<TModel>(this IDbConnection connection, TModel @object, IUser user = null, string tableName = null)
{
await GetProvider().UpdateAsync(connection, @object, user, tableName);
}
public static void Update<TModel>(this IDbConnection connection, TModel @object, IUser user, params Expression<Func<TModel, object>>[] setColumns)
{
GetProvider().Update(connection, @object, user, setColumns);
}
public async static Task UpdateAsync<TModel>(this IDbConnection connection, TModel @object, IUser user, params Expression<Func<TModel, object>>[] setColumns)
{
await GetProvider().UpdateAsync(connection, @object, user, setColumns);
}
public static void Delete<TModel>(this IDbConnection connection, int id, IUser user = null, string tableName = null)
{
GetProvider().Delete<TModel>(connection, id, user, tableName);
}
public async static Task DeleteAsync<TModel>(this IDbConnection connection, int id, IUser user = null, string tableName = null)
{
await GetProvider().DeleteAsync<TModel>(connection, id, user, tableName);
}
public static void CreateTable<TModel>(this IDbConnection connection, string tableName = null)
{
GetProvider().CreateTable<TModel>(connection, tableName);
}
}
}