Пример #1
0
 public async Task <int> ExecuteNonQueryAsync(ExecutableQueryExpression query, ParameterBag parameters = null, CancellationToken cancellationToken = default)
 {
     var(sql, autoParameters) = ConvertQuery(query);
     using (var lease = await OpenConnectionAsync(cancellationToken))
         using (var command = CreateCommand(lease.Connection, sql, ParameterBag.Combine(autoParameters, parameters)))
         {
             return(await command.ExecuteNonQueryAsync(cancellationToken));
         }
 }
Пример #2
0
 public int ExecuteNonQuery(ExecutableQueryExpression query, ParameterBag parameters = null)
 {
     var(sql, autoParameters) = ConvertQuery(query);
     using (var lease = OpenConnection())
         using (var command = CreateCommand(lease.Connection, sql, ParameterBag.Combine(autoParameters, parameters)))
         {
             return(command.ExecuteNonQuery());
         }
 }
Пример #3
0
        public virtual QueryResult ExecuteReader(ExecutableQueryExpression query, ParameterBag parameters = null)
        {
            var(sql, autoParameters) = ConvertQuery(query);
            var lease   = OpenConnection();
            var command = CreateCommand(lease.Connection, sql, ParameterBag.Combine(autoParameters, parameters));

            try
            {
                var reader = command.ExecuteReader();
                return(new QueryResult(command, reader, lease));
            }
            catch
            {
                command.Dispose();
                lease.Dispose();
                throw;
            }
        }
Пример #4
0
        public virtual async Task <QueryResult> ExecuteReaderAsync(ExecutableQueryExpression query, ParameterBag parameters = null, CancellationToken cancellationToken = default)
        {
            var(sql, autoParameters) = ConvertQuery(query);
            var lease = await OpenConnectionAsync(cancellationToken);

            var command = CreateCommand(lease.Connection, sql, ParameterBag.Combine(autoParameters, parameters));

            try
            {
                var reader = await command.ExecuteReaderAsync(cancellationToken);

                return(new QueryResult(command, reader, lease));
            }
            catch
            {
                command.Dispose();
                lease.Dispose();
                throw;
            }
        }
Пример #5
0
        public async Task <QueryResult> ExecuteReaderAsync(ExecutableQueryExpression query, ParameterBag parameters = null, CancellationToken cancellationToken = default)
        {
            var(sql, autoParameters) = _queryProvider.ConvertQuery(query);
            var command = _queryProvider.CreateCommand(_connectionLease.Connection, sql, ParameterBag.Combine(autoParameters, parameters));

            try
            {
                command.Transaction = _transaction;
                var reader = await command.ExecuteReaderAsync();

                return(new QueryResult(command, reader, new RemainOpenConnectionLease(_connectionLease.Connection)));
            }
            catch
            {
                command.Dispose();
                throw;
            }
        }
Пример #6
0
        public QueryResult ExecuteReader(ExecutableQueryExpression query, ParameterBag parameters = null)
        {
            var(sql, autoParameters) = _queryProvider.ConvertQuery(query);
            var command = _queryProvider.CreateCommand(_connectionLease.Connection, sql, ParameterBag.Combine(autoParameters, parameters));

            try
            {
                command.Transaction = _transaction;
                var reader = command.ExecuteReader();
                return(new QueryResult(command, reader, new RemainOpenConnectionLease(_connectionLease.Connection)));
            }
            catch
            {
                command.Dispose();
                throw;
            }
        }
Пример #7
0
 public Task <int> ExecuteNonQueryAsync(ExecutableQueryExpression query, ParameterBag parameters = null, CancellationToken cancellationToken = default)
 {
     var(sql, autoParameters) = _queryProvider.ConvertQuery(query);
     using (var command = _queryProvider.CreateCommand(_connectionLease.Connection, sql, ParameterBag.Combine(autoParameters, parameters)))
     {
         command.Transaction = _transaction;
         return(command.ExecuteNonQueryAsync());
     }
 }
Пример #8
0
 public int ExecuteNonQuery(ExecutableQueryExpression query, ParameterBag parameters = null)
 {
     var(sql, autoParameters) = _queryProvider.ConvertQuery(query);
     using (var command = _queryProvider.CreateCommand(_connectionLease.Connection, sql, ParameterBag.Combine(autoParameters, parameters)))
     {
         command.Transaction = _transaction;
         return(command.ExecuteNonQuery());
     }
 }