using EntrustSettle.Common.DB; using SqlSugar; using System; namespace EntrustSettle.Common.Seed { public class SeedContext { private static MutiDBOperate connectObject => GetMainConnectionDb(); private static string _connectionString = connectObject.Connection; private static DbType _dbType = (DbType)connectObject.DbType; public static string ConnId = connectObject.ConnId; private SqlSugarScope _db; /// /// 连接字符串 /// public static MutiDBOperate GetMainConnectionDb() { var mainConnetctDb = BaseDBConfig.MutiConnectionString.allDbs.Find(x => x.ConnId == MainDb.CurrentDbConnId); if (BaseDBConfig.MutiConnectionString.allDbs.Count > 0) { if (mainConnetctDb == null) { mainConnetctDb = BaseDBConfig.MutiConnectionString.allDbs[0]; } } else { throw new Exception("请确保appsettigns.json中配置连接字符串,并设置Enabled为true;"); } return mainConnetctDb; } /// /// 连接字符串 /// public static string ConnectionString { get { return _connectionString; } set { _connectionString = value; } } /// /// 数据库类型 /// public static DbType DbType { get { return _dbType; } set { _dbType = value; } } /// /// 数据连接对象 /// public SqlSugarScope Db { get { return _db; } private set { _db = value; } } /// /// 功能描述:构造函数 /// public SeedContext(ISqlSugarClient sqlSugarClient) { if (string.IsNullOrEmpty(_connectionString)) throw new ArgumentNullException("数据库连接字符串为空"); _db = sqlSugarClient as SqlSugarScope; } /// /// 功能描述:获取数据库处理对象 /// public SimpleClient GetEntityDB() where T : class, new() { return new SimpleClient(_db); } } }