System.Data.Common.DbCommand.ExecuteScalarAsync(System.Threading.CancellationToken)

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 7

1. Example

Project: linq2db
Source File: RetryingDbCommand.cs
View license
public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken)
		{
			return _policy.ExecuteAsync(ct => _command.ExecuteScalarAsync(ct), cancellationToken);
		}

2. Example

Project: linq2db
Source File: DataConnection.Async.cs
View license
internal 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;
			}
		}

3. Example

Project: referencesource
Source File: DBCommand.cs
View license
public Task<object> ExecuteScalarAsync() {
            return ExecuteScalarAsync(CancellationToken.None);
        }

4. Example

View license
public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken)
        {
            return base.ExecuteScalarAsync(cancellationToken);
        }

5. Example

Project: elastic-db-tools
Source File: MockSqlCommand.cs
View license
public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken)
        {
            return base.ExecuteScalarAsync(cancellationToken);
        }

6. Example

Project: SmartStoreNET
Source File: CachingCommand.cs
View license
public 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;
		}

7. Example

Project: effort
Source File: DbCommandWrapper.cs
View license
public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                var cancelled = new TaskCompletionSource<object>();
                cancelled.SetCanceled();

                return cancelled.Task;
            }

            return this.wrappedCommand.ExecuteScalarAsync(cancellationToken);
        }

8. Example

View license
public 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);
            }
        }

9. Example

Project: elephant
Source File: DbConnectionExtensions.cs
View license
public 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));
            }
        }

10. Example

View license
private 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)));
				}
			}
		}

11. Example

Project: nhibernate-core
Source File: TableGenerator.cs
View license
public override async Task<object> DoWorkInCurrentTransactionAsync(ISessionImplementor session/n ..... /n //View Source file for more details /n }

12. Example

Project: nhibernate-core
Source File: TableStructure.cs
View license
public override async Task<object> DoWorkInCurrentTransactionAsync(ISessionImplementor session/n ..... /n //View Source file for more details /n }

13. Example

Project: Susanoo
Source File: DatabaseManager.cs
View license
public 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();
            }
        }

14. Example

Project: Projac
Source File: SqlCommandExecutor.cs
View license
public 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();
                }
            }
        }

15. Example

View license
protected override async Task<object> ExecuteAsync(
                    IRelationalConnection /n ..... /n //View Source file for more details /n }