Example #1
0
        public virtual async Task <object> ExecuteAsync(
            [NotNull] RelationalConnection connection,
            [NotNull] Func <Task <object> > action,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(connection, "connection");

            // TODO Deal with suppressing transactions etc.

            var connectionWasOpen = connection.DbConnection.State == ConnectionState.Open;

            if (!connectionWasOpen)
            {
                Logger.OpeningConnection(connection.ConnectionString);

                await connection.OpenAsync(cancellationToken).WithCurrentCulture();
            }

            try
            {
                return(await action().WithCurrentCulture());
            }
            finally
            {
                if (!connectionWasOpen)
                {
                    Logger.ClosingConnection(connection.ConnectionString);

                    connection.Close();
                }
            }
        }
Example #2
0
        public virtual object Execute(
            [NotNull] RelationalConnection connection,
            [NotNull] Func <object> action)
        {
            Check.NotNull(connection, "connection");

            // TODO Deal with suppressing transactions etc.

            var connectionWasOpen = connection.DbConnection.State == ConnectionState.Open;

            if (!connectionWasOpen)
            {
                Logger.OpeningConnection(connection.ConnectionString);

                connection.Open();
            }

            try
            {
                return(action());
            }
            finally
            {
                if (!connectionWasOpen)
                {
                    Logger.ClosingConnection(connection.ConnectionString);

                    connection.Close();
                }
            }
        }
Example #3
0
                public void Dispose()
                {
                    if (_reader != null)
                    {
                        _reader.Dispose();
                    }

                    if (_command != null)
                    {
                        _command.Dispose();
                    }

                    if (_connection != null)
                    {
                        _connection.Close();
                    }
                }
Example #4
0
        public override async Task <int> SaveChangesAsync(
            IReadOnlyList <StateEntry> stateEntries,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(stateEntries, "stateEntries");

            var commands = _batchPreparer.BatchCommands(stateEntries);

            await _connection.OpenAsync(cancellationToken);

            try
            {
                await _batchExecutor.ExecuteAsync(commands, cancellationToken);
            }
            finally
            {
                _connection.Close();
            }

            // TODO Return the actual results once we can get them
            return(stateEntries.Count());
        }