Exemplo n.º 1
0
        /// <summary>
        /// Bulk copies a set of objects to the server.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (transaction != null)
            {
                throw new ArgumentException("DB2Provider does not support external transactions for bulk copy", "transaction");
            }

            DB2BulkCopyOptions db2Options = DB2BulkCopyOptions.Default;

            if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
            {
                db2Options |= DB2BulkCopyOptions.KeepIdentity;
            }
            if (options.HasFlag(InsightBulkCopyOptions.TableLock))
            {
                db2Options |= DB2BulkCopyOptions.TableLock;
            }
            if (options.HasFlag(InsightBulkCopyOptions.Truncate))
            {
                db2Options |= DB2BulkCopyOptions.Truncate;
            }

            using (var bulk = new DB2BulkCopy((DB2Connection)connection, db2Options))
                using (var insightBulk = new DB2InsightBulkCopy(bulk))
                {
                    bulk.DestinationTableName = tableName;

                    // map the columns by name, in case we skipped a readonly column
                    foreach (DataRow row in reader.GetSchemaTable().Rows)
                    {
                        bulk.ColumnMappings.Add((string)row["ColumnName"], (string)row["ColumnName"]);
                    }

                    if (configure != null)
                    {
                        configure(insightBulk);
                    }
                    bulk.WriteToServer(reader);
                }
        }
Exemplo n.º 2
0
 public DB2BulkCopy(DB2Connection connection, DB2BulkCopyOptions options) => throw new NotImplementedException();