Beispiel #1
0
 public RepositoryDbContext(string conString, DatabaseType dbType)
 {
     _conString = conString;
     _dbType    = dbType;
     RefreshDb();
     DbModelFactory.AddObserver(this);
 }
Beispiel #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             _db?.Dispose();
         }
         _transaction = null;
         DbModelFactory.RemoveObserver(this);
         disposedValue = false;
     }
 }
Beispiel #3
0
        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;
        }
Beispiel #4
0
        private Type CheckModel(Type type)
        {
            Type model = DbModelFactory.GetModel(type);

            return(model);
        }