-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cs
62 lines (60 loc) · 2.04 KB
/
Config.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
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Common
{
public class Config
{
public static string ConnectionString { get; set; }
/// <summary>
/// SqlSugar静态执行方法
/// </summary>
public static T StartSqlSugar<T>(Func<SqlSugar.SqlSugarClient,T> func)
{
using (SqlSugar.SqlSugarClient db = new SqlSugar.SqlSugarClient(new ConnectionConfig
{
ConnectionString = Config.ConnectionString, //必填
DbType = DbType.SqlServer, //必填
IsAutoCloseConnection = true, //默认false
InitKeyType=InitKeyType.Attribute
}))
{
return func(db);
}
}
/// <summary>
/// SqlSugar静态执行方法
/// </summary>
public static void StartSqlSugar(Action<SqlSugar.SqlSugarClient> func)
{
using (SqlSugar.SqlSugarClient db = new SqlSugar.SqlSugarClient(new ConnectionConfig
{
ConnectionString = Config.ConnectionString, //必填
DbType = DbType.SqlServer, //必填
IsAutoCloseConnection = true, //默认false
InitKeyType = InitKeyType.Attribute
}))
{
func(db);
}
}
public static SqlSugarClient GetInstance()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true
});
db.Ado.IsEnableLogEvent = true;
db.Ado.LogEventStarting = (sql, pars) =>
{
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
Console.WriteLine();
};
return db;
}
}
}