public RepositoryDbContext(string conString, DatabaseType dbType) { _conString = conString; _dbType = dbType; RefreshDb(); DbModelFactory.AddObserver(this); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { _db?.Dispose(); } _transaction = null; DbModelFactory.RemoveObserver(this); disposedValue = false; } }
public void RefreshDb() { //重用DbConnection,使用底层相同的DbConnection,支持Model持续更新 DbConnection con = null; if (_transaction != null) { con = _transaction.Connection; } else { con = _db?.Database?.GetDbConnection() ?? DbProviderFactoryHelper.GetDbConnection(_conString, _dbType); } var dBCompiledModel = DbModelFactory.GetDbCompiledModel(_conString, _dbType); _db = new BaseDbContext(_dbType, con, dBCompiledModel); _db.Database.UseTransaction(_transaction); disposedValue = false; }
private Type CheckModel(Type type) { Type model = DbModelFactory.GetModel(type); return(model); }