Exemplo n.º 1
0
        /// <summary>
        /// Write out the current batch to the underlying data store.
        /// </summary>
        private void WriteBufferToDataStore()
        {
            using (var batch = CopyAndClearBuffer())
                using (var command = commandTemplate.Clone())
                    using (var connection = dialect.OpenConnection())
                        using (var dataAdapter = dialect.Provider.CreateDataAdapter())
                            using (var transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted))
                            {
                                Debug.Assert(dataAdapter != null);

                                command.Connection       = connection;
                                command.Transaction      = transaction;
                                command.UpdatedRowSource = UpdateRowSource.None;

                                dataAdapter.InsertCommand         = (DbCommand)command;
                                dataAdapter.ContinueUpdateOnError = true;
                                dataAdapter.UpdateBatchSize       = batchSize;
                                dataAdapter.Update(batch);

                                transaction.Commit();
                            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the specified command.
        /// </summary>
        /// <param name="dialect">The <see cref="IDbDialect"/>.</param>
        /// <param name="command">The command to execute.</param>
        /// <param name="executor">The executor used to execute the command.</param>
        private static TResult ExecuteCommand <TResult>(this IDbDialect dialect, IDbCommand command, Func <TResult> executor)
        {
            TResult result;

            try
            {
                using (var connection = dialect.OpenConnection())
                    using (var transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted))
                    {
                        command.Connection  = connection;
                        command.Transaction = transaction;

                        result = executor();

                        transaction.Commit();
                    }
            }
            catch (DbException ex)
            {
                throw dialect.Translate(command, ex);
            }

            return(result);
        }