Here are the examples of the csharp api class System.Data.Common.DbCommand.ExecuteScalarAsync(System.Threading.CancellationToken) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
15 Examples
0
1. Example
View licensepublic override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken) { return _policy.ExecuteAsync(ct => _command.ExecuteScalarAsync(ct), cancellationToken); }
0
2. Example
View licenseinternal async Task<object> ExecuteScalarAsync(CancellationToken cancellationToken) { if (TraceSwitch.Level == TraceLevel.Off || OnTraceConnection == null) return await ((DbCommand)Command).ExecuteScalarAsync(cancellationToken); if (TraceSwitch.TraceInfo) { OnTraceConnection(new TraceInfo(TraceInfoStep.BeforeExecute) { TraceLevel = TraceLevel.Info, DataConnection = this, Command = Command, IsAsync = true, }); } try { var now = DateTime.Now; var ret = await ((DbCommand)Command).ExecuteScalarAsync(cancellationToken); if (TraceSwitch.TraceInfo) { OnTraceConnection(new TraceInfo(TraceInfoStep.AfterExecute) { TraceLevel = TraceLevel.Info, DataConnection = this, Command = Command, ExecutionTime = DateTime.Now - now, IsAsync = true, }); } return ret; } catch (Exception ex) { if (TraceSwitch.TraceError) { OnTraceConnection(new TraceInfo(TraceInfoStep.Error) { TraceLevel = TraceLevel.Error, DataConnection = this, Command = Command, Exception = ex, IsAsync = true, }); } throw; } }
0
3. Example
View licensepublic Task<object> ExecuteScalarAsync() { return ExecuteScalarAsync(CancellationToken.None); }
0
4. Example
View licensepublic override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken) { return base.ExecuteScalarAsync(cancellationToken); }
0
5. Example
View licensepublic override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken) { return base.ExecuteScalarAsync(cancellationToken); }
0
6. Example
View licensepublic async override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken) { if (!IsCacheable) { return await _command.ExecuteScalarAsync(cancellationToken); } var key = CreateKey(); object value; if (_cacheTransactionInterceptor.GetItem(Transaction, key, out value)) { return value; } value = await _command.ExecuteScalarAsync(cancellationToken); // TODO: somehow determine expiration TimeSpan? duration = null; _cacheTransactionInterceptor.PutItem( Transaction, key, value, _commandTreeFacts.AffectedEntitySets.Select(s => s.Name), duration); return value; }
0
7. Example
View licensepublic override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { var cancelled = new TaskCompletionSource<object>(); cancelled.SetCanceled(); return cancelled.Task; } return this.wrappedCommand.ExecuteScalarAsync(cancellationToken); }
0
8. Example
View licensepublic Task<object> ExecuteScalarAsync(SqlQueryCommand command, CancellationToken cancellationToken) { if (command == null) throw new ArgumentNullException("command"); using (var dbCommand = _dbConnection.CreateCommand()) { dbCommand.Connection = _dbConnection; dbCommand.CommandTimeout = _commandTimeout; dbCommand.CommandType = command.Type; dbCommand.CommandText = command.Text; dbCommand.Parameters.AddRange(command.Parameters); return dbCommand.ExecuteScalarAsync(cancellationToken); } }
0
9. Example
View licensepublic static async Task<TResult> ExecuteScalarAsync<TResult>( this DbConnection connection, string commandText, CancellationToken cancellationToken, SqlParameter[] sqlParameters = null) { using (var command = connection.CreateCommand()) { command.CommandText = commandText; command.CommandType = System.Data.CommandType.Text; if (sqlParameters != null && sqlParameters.Length > 0) { command.Parameters.AddRange(sqlParameters); } return (TResult)(await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false)); } }
0
10. Example
View licenseprivate async Task<int> GetEstablishedConnectionsAsync(CancellationToken cancellationToken = default(CancellationToken)) { using (var conn = _driver.CreateConnection()) { conn.ConnectionString = _connectionString; await (conn.OpenAsync(cancellationToken)); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "select count(*) from mon$attachments where mon$attachment_id <> current_connection"; return Convert.ToInt32(await (cmd.ExecuteScalarAsync(cancellationToken))); } } }
0
11. Example
View licensepublic override async Task<object> DoWorkInCurrentTransactionAsync(ISessionImplementor session/n ..... /n //View Source file for more details /n }
0
12. Example
View licensepublic override async Task<object> DoWorkInCurrentTransactionAsync(ISessionImplementor session/n ..... /n //View Source file for more details /n }
0
13. Example
View licensepublic async Task<T> ExecuteScalarAsync<T>(string commandText, CommandType commandType, TimeSpan commandTimeout, CancellationToken cancellationToken = default(CancellationToken), params DbParameter[] parameters) { if (string.IsNullOrWhiteSpace(commandText)) throw new ArgumentNullException(nameof(commandText)); var open = _explicitlyOpened; try { OpenConnectionInternal(); using (var command = PrepCommand(Connection, commandText, commandType, commandTimeout, parameters)) { return CastValue<T>(await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false)); } } finally { #if !DOTNETCORE if (Transaction.Current == null && !open) #else if (Transaction == null && !open) #endif CloseConnection(); } }
0
14. Example
View licensepublic async Task<object> ExecuteScalarAsync(SqlQueryCommand command, CancellationToken cancellationToken) { if (command == null) throw new ArgumentNullException("command"); using (var dbConnection = _dbProviderFactory.CreateConnection()) { dbConnection.ConnectionString = _settings.ConnectionString; await dbConnection.OpenAsync(cancellationToken); try { using (var dbCommand = dbConnection.CreateCommand()) { dbCommand.Connection = dbConnection; dbCommand.CommandTimeout = _commandTimeout; dbCommand.CommandType = command.Type; dbCommand.CommandText = command.Text; dbCommand.Parameters.Clear(); dbCommand.Parameters.AddRange(command.Parameters); return dbCommand.ExecuteScalarAsync(cancellationToken); } } finally { dbConnection.Close(); } } }
0
15. Example
View licenseprotected override async Task<object> ExecuteAsync( IRelationalConnection /n ..... /n //View Source file for more details /n }