Пример #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="conString">数据库连接名或连接字符串</param>
 /// <param name="dbType">数据库类型</param>
 /// <param name="entityNamespace">数据库实体命名空间,注意,该命名空间应该包含所有需要的数据库实体</param>
 public RepositoryDbContext(string conString, DatabaseType dbType)
 {
     _conString = conString;
     _dbType    = dbType;
     RefreshDb();
     DbModelFactory.AddObserver(this);
 }
Пример #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             _db?.Dispose();
         }
         _transaction = null;
         DbModelFactory.RemoveObserver(this);
         disposedValue = true;
     }
 }
Пример #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;
        }
Пример #4
0
        private Type CheckModel(Type type)
        {
            Type model = DbModelFactory.GetModel(type);

            return(model);
        }