コード例 #1
0
ファイル: RestmeDb.cs プロジェクト: oelite/RESTme.Dapper
 public RestmeDb(ILogger logger = null)
 {
     if (logger != null)
     {
         Logger = logger;
     }
     if (DefaultConnectionString.IsNullOrEmpty())
     {
         throw new ArgumentException(
                   $"DefaultConnectionString is not present - try instantiate {this.GetType().Name} with a valid connection string first.");
     }
 }
コード例 #2
0
ファイル: RestmeDb.cs プロジェクト: oelite/RESTme.Dapper
        private async Task <IDbConnection> GetOpenConnectionAsync(bool establishTransaction = false,
                                                                  string connectionString   = null)
        {
            if (_currentConnection == null || _currentConnection.State == ConnectionState.Closed)
            {
                connectionString ??= _dbConnectionString;
                _currentConnection = new SqlConnection(connectionString);
                await((SqlConnection)_currentConnection).OpenAsync();
            }

            ;

            if (DefaultConnectionString.IsNullOrEmpty())
            {
                DefaultConnectionString = connectionString;
            }

            if (establishTransaction)
            {
                await GetDbTransactionAsync();
            }

            return(_currentConnection);
        }