31 lines
913 B
C#
31 lines
913 B
C#
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;
|
||
|
|
}
|
||
|
|
}
|