/// <summary> /// 初始化DB /// </summary> private void Init(DbConfModel conf) { if (conf.IsLog) { DBConf.DbSqlLoged += Logger.Sql.Info; } DBConf.DbSqlErrorLoged += Logger.Sql.Error; //try //{ // var tables = SysConf.SysContainer.Assemblies.SelectMany(x => x.Types.Where(p=>typeof(IEntity).IsAssignableFrom(p) && !p.IsAbstract)).ToArray(); // if (tables.Any()) // { // var db = new Repository(); // db.DbContext.CodeFirst.InitTables(tables); // } // Logger.Main.Info($"[DataAccess] startup { DBConf.CnfModel.DbType} {tables?.Length ?? 0} table init "); //} //catch (System.Exception ex) //{ // Logger.Main.Error($"[DataAccess] startup { DBConf.CnfModel.DbType} init fail, {ex.Message}"); //} var dbContext = CallContext.GetData("DBContext") as DbContext; if (dbContext == null) { dbContext = new DbContext(conf); CallContext.SetData("DBContext", dbContext); } DbContext = dbContext.Db; }
public DbContext(DbConfModel conf) { DbConf = conf; GetConn(); }
/// <summary> /// 构造函数 /// </summary> public Repository(DbConfModel conf) { Init(conf); }