You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using Custom.Utils.Framework ;
using SqlSugar ;
using System ;
namespace Production_Oil.Services
{
public partial class DbContext
{
/// <summary>
/// 连接符字串
/// $"Server={Server};Port={Port};Database={Database};User Id={UserId};Password={passWord}"
/// </summary>
public static string ConnStr = "" ;
public static SqlSugarScope db = null ;
public static void GetConStr ( string server , string port , string database , string userId , string passWord , bool isEncrypt , string schema )
{
if ( isEncrypt )
{
// 解密
passWord = DesHelper . DecryptStringFromBytes_Aes ( passWord ) ;
}
ConnStr = $"Server={server};Port={port};Database={database};User Id={userId};Password={passWord};Search Path={schema}" ;
}
public DbContext ( )
{
//用单例模式
db = new SqlSugarScope ( new ConnectionConfig ( )
{
ConnectionString = ConnStr , //连接符字串
DbType = DbType . PostgreSQL , //数据库类型
IsAutoCloseConnection = true , //不设成true要手动close
} ,
db = >
{
//(A)全局生效配置点
//调试SQL事件, 可以删掉
db . Aop . OnLogExecuting = ( sql , pars ) = >
{
Console . WriteLine ( sql ) ; //输出sql,查看执行sql
} ;
} ) ;
AppContext . SetSwitch ( "Npgsql.EnableLegacyTimestampBehavior" , true ) ;
AppContext . SetSwitch ( "Npgsql.DisableDateTimeInfinityConversions" , true ) ;
}
}
}