예제 #1
0
        /// <summary>
        /// 使用指定的连接字符串和<see cref="DbProviderFactory"/>实例初始化<see cref="DbClient"/>的新实例。
        /// </summary>
        /// <param name="connectionString">连接字符串。</param>
        /// <param name="factory"><see cref="DbProviderFactory"/>实例</param>
        public DbClient(string connectionString, DbProviderFactory factory)
        {
            ArgAssert.NotNull(factory, nameof(factory));
            ArgAssert.NotNullOrEmptyOrWhitespace(connectionString, nameof(connectionString));

            _factory         = factory;
            ConnectionString = connectionString;
        }
예제 #2
0
        /// <summary>
        /// 使用指定的连接字符串和<see cref="DbProviderFactory"/>工厂初始化<see cref="DbClient"/>的新实例。
        /// </summary>
        /// <param name="connectionString">连接字符串。</param>
        /// <param name="factoryGetter">用于创建<see cref="DbProviderFactory"/>。</param>
        public DbClient(string connectionString, Func <DbProviderFactory> factoryGetter)
        {
            ArgAssert.NotNull(factoryGetter, nameof(factoryGetter));
            ArgAssert.NotNullOrEmptyOrWhitespace(connectionString, nameof(connectionString));

            _factoryGetter   = factoryGetter;
            ConnectionString = connectionString;
        }
예제 #3
0
        private ThreadLocalTransactionKeeper(DbProviderFactory dbProviderFactory, string connectionString)
        {
            ArgAssert.NotNull(dbProviderFactory, "dbProviderFactory");
            ArgAssert.NotNullOrEmptyOrWhitespace(connectionString, "connectionString");

            _factory          = dbProviderFactory;
            _connectionString = connectionString;
        }
예제 #4
0
        /// <summary>
        /// 创建<see cref="ThreadLocalTransactionKeeper"/>的新实例。
        /// </summary>
        /// <param name="dbProviderFactory"><see cref="DbProviderFactory"/>实例。</param>
        /// <param name="connectionString">初始化数据库连接的连接字符串。</param>
        /// <param name="commandTimeout">
        /// 指定事务内的命令的默认执行超时时间,当方法没有单独制定超时时,套用此超时值。
        /// </param>
        public ThreadLocalTransactionKeeper(
            DbProviderFactory dbProviderFactory, string connectionString, int commandTimeout)
        {
            ArgAssert.NotNull(dbProviderFactory, nameof(dbProviderFactory));
            ArgAssert.NotNullOrEmptyOrWhitespace(connectionString, nameof(connectionString));

            Factory          = dbProviderFactory;
            ConnectionString = connectionString;
            DefaultTimeout   = commandTimeout;
        }
        public TransactionScopeTransactionKeeper(DbProviderFactory dbProviderFactory, string connectionString)
        {
            ArgAssert.NotNull(dbProviderFactory, "dbProviderFactory");
            ArgAssert.NotNullOrEmptyOrWhitespace(connectionString, "connectionString");

            _factory          = dbProviderFactory;
            _connectionString = connectionString;

            //鉴于应用场景,直接开启事务控制(不过数据库连接还没初始化)
            _tran = new TransactionScope();
        }
예제 #6
0
        /// <summary>
        /// 初始化类型的新实例。
        /// </summary>
        /// <param name="dbProviderFactory"><see cref="DbProviderFactory"/>的实例。</param>
        /// <param name="connectionString">指定数据库的连接字符串。</param>
        /// <param name="commandTimeout">
        /// 指定事务内的命令的默认执行超时时间,当方法没有单独制定超时时,套用此超时值。
        /// </param>
        public TransactionScopeTransactionKeeper(
            DbProviderFactory dbProviderFactory, string connectionString, int commandTimeout)
        {
            ArgAssert.NotNull(dbProviderFactory, "dbProviderFactory");
            ArgAssert.NotNullOrEmptyOrWhitespace(connectionString, "connectionString");

            Factory          = dbProviderFactory;
            ConnectionString = connectionString;
            DefaultTimeout   = commandTimeout;

            //鉴于应用场景,直接开启事务控制(不过数据库连接还没初始化)
            _tran = new TransactionScope();
        }
예제 #7
0
 /// <summary>
 /// 使用指定的数据库类型和连接字符串初始化<see cref="SqlDbClient"/>的新实例。
 /// </summary>
 /// <param name="connectionString">连接字符串。</param>
 public MysqlDbClient(string connectionString)
 {
     ArgAssert.NotNullOrEmptyOrWhitespace(connectionString, "connectionString");
     ConnectionString = connectionString;
 }