示例#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();
                }
            }
        }
示例#2
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());
        }