GlobalVar.cs
1.39 KB
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
using FreeSql;
using FreeSql.SqlServer;
using System.Data.SqlClient;
namespace HHECS.DAQHandle
{
internal static class GlobalVar
{
public static IFreeSql FreeSql;
private static string _connectionString;
/// <summary>
/// 数据库连接字符串
/// </summary>
public static string ConnectionString => _connectionString;
/// <summary>
/// 设置数据库连接字符串
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
public static void SetConnectionString(string connectionString)
{
_connectionString = connectionString;
FreeSql = new FreeSqlBuilder()
//.UseConnectionString(DataType.SqlServer, GetConnectionString())
.UseConnectionFactory(DataType.SqlServer, () => new SqlConnection(ConnectionString), typeof(SqlServerProvider<>))
.UseMonitorCommand(cmd => cmd.CommandTimeout = 60, null)
//监听SQL语句
//.UseMonitorCommand(cmd =>
//{
// if (cmd.CommandText.ToLower().Contains("delete"))
// Console.WriteLine($"Sql:{cmd.CommandText}");
//})
.UseAutoSyncStructure(false) //自动同步实体结构到数据库,FreeSql不会扫描程序集,只有CRUD时才会生成表。
.Build();
}
}
}