Files
1440WGJ/JY.DAL/Repository/DataContext.cs
T

31 lines
913 B
C#
Raw Normal View History

2026-07-14 13:55:17 +08:00
using SqlSugar;
using System;
using System.Configuration;
namespace JY.DAL.Repository
{
public static class DataContext
{
private static readonly Lazy<SqlSugarScope> _instance = new Lazy<SqlSugarScope>(() =>
{
string connectionString = ConfigurationManager.ConnectionStrings["CurDB"].ConnectionString;
return new SqlSugarScope(new ConnectionConfig
{
ConnectionString = connectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
}, db =>
{
db.Aop.OnLogExecuting = (sql, pars) =>
{
#if DEBUG
Console.WriteLine($"SqlSugar SQL: {sql}");
#endif
};
});
});
public static SqlSugarScope Instance => _instance.Value;
}
}