Ejemplo n.º 1
0
        public void Insert(IDatabase database, IDbTransaction Transaction, DataTable dataTable, int batchSize = 4096, Action <int> completePercentage = null, SqlBulkCopyOptions sqlBulkCopyOptions = SqlBulkCopyOptions.Default)
        {
            if (BatcherChecker.CheckDataTable(dataTable))
            {
                try
                {
                    if (Transaction == null)
                    {
                        Transaction = database.Transaction;
                    }

                    using (var bulkCopy = new SqlBulkCopy(SqlConnectionResolver(database.Connection), sqlBulkCopyOptions, SqlTransactionResolver(Transaction)))
                    {
                        bulkCopy.BatchSize            = batchSize;
                        bulkCopy.DestinationTableName = dataTable.TableName;

                        bulkCopy.WriteToServer(dataTable);
                    }
                }
                catch (Exception exception)
                {
                    throw new PureDataException("SqlServerBatcher Insert", exception);
                }
            }
        }
Ejemplo n.º 2
0
        public void Insert <T>(IDatabase database, IDbTransaction Transaction, IEnumerable <T> list, string tableName, int batchSize = 4096, Action <int> completePercentage = null, SqlBulkCopyOptions sqlBulkCopyOptions = SqlBulkCopyOptions.Default)
        {
            if (BatcherChecker.CheckList <T>(list, tableName))
            {
                DataTable dt = ChangeToTable <T>(list.ToList(), tableName);

                this.Insert(database, Transaction, dt, batchSize, completePercentage, sqlBulkCopyOptions);
            }
        }