Esempio n. 1
0
        protected virtual async Task ExecuteBatchAsync(
            [NotNull] ModificationCommandBatch commandBatch,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(commandBatch, "commandBatch");

            // TODO: It is likely the code below won't really work correctly in the wild because
            // we currently don't actually create batches of commands and because there is no mechanism
            // for getting back affected rows for update/delete commands. Leaving the code here right now
            // because it might be a decent starting point for a real implementation.

            using (var storeCommand = CreateStoreCommand(Connection.DbConnection, commandBatch))
            {
                var modificationCommands = commandBatch.ModificationCommands;
                using (var reader = await storeCommand.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false))
                {
                    var commandIndex = -1;
                    do
                    {
                        commandIndex++;
                        var tableModification = modificationCommands[commandIndex];

                        if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
                        {
                            if (!tableModification.RequiresResultPropagation)
                            {
                                throw new DbUpdateConcurrencyException(string.Format(Strings.FormatUpdateConcurrencyException(0, 1)));
                            }

                            tableModification.PropagateResults(new RelationalTypedValueReader(reader));

                            if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
                            {
                                throw new DbUpdateException(Strings.TooManyRowsForModificationCommand);
                            }
                        }
                        else
                        {
                            if (tableModification.RequiresResultPropagation)
                            {
                                throw new DbUpdateConcurrencyException(string.Format(Strings.FormatUpdateConcurrencyException(1, 0)));
                            }
                        }
                    }while (await reader.NextResultAsync(cancellationToken).ConfigureAwait(false));
                }
            }
        }
 public virtual bool AddCommand(
     ModificationCommandBatch modificationCommandBatch,
     ModificationCommand modificationCommand)
 => Check.NotNull(modificationCommandBatch, nameof(modificationCommandBatch))
 .AddCommand(Check.NotNull(modificationCommand, nameof(modificationCommand)));
 public virtual bool AddCommand(
     ModificationCommandBatch modificationCommandBatch,
     ModificationCommand modificationCommand)
     => Check.NotNull(modificationCommandBatch, nameof(modificationCommandBatch))
         .AddCommand(Check.NotNull(modificationCommand, nameof(modificationCommand)));