Esempio n. 1
0
        /// <summary>
        /// Bulk update an instance of <see cref="DbDataReader"/> object into the database in an asynchronous way.
        /// </summary>
        /// <param name="repository">The instance of <see cref="DbRepository{TDbConnection}"/> object.</param>
        /// <param name="tableName">The target table for bulk-update operation.</param>
        /// <param name="reader">The <see cref="DbDataReader"/> object to be used in the bulk-update operation.</param>
        /// <param name="qualifiers">The qualifier fields to be used for this bulk-update operation. This is defaulted to the primary key; if not present, then it will use the identity key.</param>
        /// <param name="mappings">The list of the columns to be used for mappings. If this parameter is not set, then all columns will be used for mapping.</param>
        /// <param name="options">The bulk-copy options to be used.</param>
        /// <param name="hints">The table hints to be used.</param>
        /// <param name="batchSize">The size per batch to be used.</param>
        /// <param name="usePhysicalPseudoTempTable">The flags that signify whether to create a physical pseudo table.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param>
        /// <returns>The number of rows affected by the execution.</returns>
        public static async Task <int> BulkUpdateAsync(this DbRepository <SqlConnection> repository,
                                                       string tableName,
                                                       DbDataReader reader,
                                                       IEnumerable <Field> qualifiers           = null,
                                                       IEnumerable <BulkInsertMapItem> mappings = null,
                                                       SqlBulkCopyOptions?options = null,
                                                       string hints  = null,
                                                       int?batchSize = null,
                                                       bool?usePhysicalPseudoTempTable     = null,
                                                       SqlTransaction transaction          = null,
                                                       CancellationToken cancellationToken = default)
        {
            // Create a connection
            using var bulkDbConnector = new BulkDbConnector(transaction, repository);

            // Call the method
            return(await bulkDbConnector.Connection.BulkUpdateAsync(tableName : tableName,
                                                                    reader : reader,
                                                                    qualifiers : qualifiers,
                                                                    mappings : mappings,
                                                                    options : options,
                                                                    hints : hints,
                                                                    bulkCopyTimeout : repository.CommandTimeout,
                                                                    batchSize : batchSize,
                                                                    usePhysicalPseudoTempTable : usePhysicalPseudoTempTable,
                                                                    transaction : transaction,
                                                                    cancellationToken : cancellationToken));
        }
Esempio n. 2
0
        /// <summary>
        /// Bulk update a list of data entity objects into the database.
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity object.</typeparam>
        /// <param name="repository">The instance of <see cref="DbRepository{TDbConnection}"/> object.</param>
        /// <param name="entities">The list of the data entities to be bulk-updated.</param>
        /// <param name="qualifiers">The expression for the qualifier fields to be used for this bulk-update operation. This is defaulted to the primary key; if not present, then it will use the identity key.</param>
        /// <param name="mappings">The list of the columns to be used for mappings. If this parameter is not set, then all columns will be used for mapping.</param>
        /// <param name="options">The bulk-copy options to be used.</param>
        /// <param name="hints">The table hints to be used.</param>
        /// <param name="batchSize">The size per batch to be used.</param>
        /// <param name="usePhysicalPseudoTempTable">The flags that signify whether to create a physical pseudo table.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <returns>The number of rows affected by the execution.</returns>
        public static int BulkUpdate <TEntity>(this DbRepository <SqlConnection> repository,
                                               IEnumerable <TEntity> entities,
                                               Expression <Func <TEntity, object> > qualifiers = null,
                                               IEnumerable <BulkInsertMapItem> mappings        = null,
                                               SqlBulkCopyOptions?options = null,
                                               string hints  = null,
                                               int?batchSize = null,
                                               bool?usePhysicalPseudoTempTable = null,
                                               SqlTransaction transaction      = null)
            where TEntity : class
        {
            // Create a connection
            using var bulkDbConnector = new BulkDbConnector(transaction, repository);

            // Call the method
            return(bulkDbConnector.Connection.BulkUpdate(entities: entities,
                                                         qualifiers: qualifiers,
                                                         mappings: mappings,
                                                         options: options,
                                                         hints: hints,
                                                         bulkCopyTimeout: repository.CommandTimeout,
                                                         batchSize: batchSize,
                                                         usePhysicalPseudoTempTable: usePhysicalPseudoTempTable,
                                                         transaction: transaction));
        }
Esempio n. 3
0
        /// <summary>
        /// Bulk update an instance of <see cref="DbDataReader"/> object into the database.
        /// </summary>
        /// <param name="repository">The instance of <see cref="DbRepository{TDbConnection}"/> object.</param>
        /// <param name="tableName">The target table for bulk-update operation.</param>
        /// <param name="dataTable">The <see cref="DataTable"/> object to be used in the bulk-update operation.</param>
        /// <param name="qualifiers">The qualifier fields to be used for this bulk-update operation. This is defaulted to the primary key; if not present, then it will use the identity key.</param>
        /// <param name="rowState">The state of the rows to be copied to the destination.</param>
        /// <param name="mappings">The list of the columns to be used for mappings. If this parameter is not set, then all columns will be used for mapping.</param>
        /// <param name="options">The bulk-copy options to be used.</param>
        /// <param name="hints">The table hints to be used.</param>
        /// <param name="batchSize">The size per batch to be used.</param>
        /// <param name="usePhysicalPseudoTempTable">The flags that signify whether to create a physical pseudo table.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <returns>The number of rows affected by the execution.</returns>
        public static int BulkUpdate(this DbRepository <SqlConnection> repository,
                                     string tableName,
                                     DataTable dataTable,
                                     IEnumerable <Field> qualifiers           = null,
                                     DataRowState?rowState                    = null,
                                     IEnumerable <BulkInsertMapItem> mappings = null,
                                     SqlBulkCopyOptions?options               = null,
                                     string hints  = null,
                                     int?batchSize = null,
                                     bool?usePhysicalPseudoTempTable = null,
                                     SqlTransaction transaction      = null)
        {
            // Create a connection
            using var bulkDbConnector = new BulkDbConnector(transaction, repository);

            // Call the method
            return(bulkDbConnector.Connection.BulkUpdate(tableName: tableName,
                                                         dataTable: dataTable,
                                                         qualifiers: qualifiers,
                                                         rowState: rowState,
                                                         mappings: mappings,
                                                         options: options,
                                                         hints: hints,
                                                         bulkCopyTimeout: repository.CommandTimeout,
                                                         batchSize: batchSize,
                                                         usePhysicalPseudoTempTable: usePhysicalPseudoTempTable,
                                                         transaction: transaction));
        }
Esempio n. 4
0
        /// <summary>
        /// Bulk merge an instance of <see cref="DbDataReader"/> object into the database in an asynchronous way.
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity object.</typeparam>
        /// <param name="repository">The instance of <see cref="DbRepository{TDbConnection}"/> object.</param>
        /// <param name="dataTable">The <see cref="DataTable"/> object to be used in the bulk-merge operation.</param>
        /// <param name="qualifiers">The qualifier fields to be used for this bulk-merge operation. This is defaulted to the primary key; if not present, then it will use the identity key.</param>
        /// <param name="rowState">The state of the rows to be copied to the destination.</param>
        /// <param name="mappings">The list of the columns to be used for mappings. If this parameter is not set, then all columns will be used for mapping.</param>
        /// <param name="options">The bulk-copy options to be used.</param>
        /// <param name="hints">The table hints to be used.</param>
        /// <param name="batchSize">The size per batch to be used.</param>
        /// <param name="isReturnIdentity">The flags that signify whether the identity values will be returned.</param>
        /// <param name="usePhysicalPseudoTempTable">The flags that signify whether to create a physical pseudo table.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param>
        /// <returns>The number of rows affected by the execution.</returns>
        public static async Task <int> BulkMergeAsync <TEntity>(this DbRepository <SqlConnection> repository,
                                                                DataTable dataTable,
                                                                IEnumerable <Field> qualifiers           = null,
                                                                DataRowState?rowState                    = null,
                                                                IEnumerable <BulkInsertMapItem> mappings = null,
                                                                SqlBulkCopyOptions?options               = null,
                                                                string hints                        = null,
                                                                int?batchSize                       = null,
                                                                bool?isReturnIdentity               = null,
                                                                bool?usePhysicalPseudoTempTable     = null,
                                                                SqlTransaction transaction          = null,
                                                                CancellationToken cancellationToken = default)
            where TEntity : class
        {
            // Create a connection
            using var bulkDbConnector = new BulkDbConnector(transaction, repository);

            // Call the method
            return(await bulkDbConnector.Connection.BulkMergeAsync <TEntity>(dataTable : dataTable,
                                                                             qualifiers : qualifiers,
                                                                             rowState : rowState,
                                                                             mappings : mappings,
                                                                             options : options,
                                                                             hints : hints,
                                                                             bulkCopyTimeout : repository.CommandTimeout,
                                                                             batchSize : batchSize,
                                                                             isReturnIdentity : isReturnIdentity,
                                                                             usePhysicalPseudoTempTable : usePhysicalPseudoTempTable,
                                                                             transaction : transaction,
                                                                             cancellationToken : cancellationToken));
        }
Esempio n. 5
0
        /// <summary>
        /// Bulk insert a list of data entity objects into the database.
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity object.</typeparam>
        /// <param name="repository">The instance of <see cref="DbRepository{TDbConnection}"/> object.</param>
        /// <param name="tableName">The target table for bulk-insert operation.</param>
        /// <param name="entities">The list of the data entities to be bulk-inserted.</param>
        /// <param name="mappings">The list of the columns to be used for mappings. If this parameter is not set, then all columns will be used for mapping.</param>
        /// <param name="options">The bulk-copy options to be used.</param>
        /// <param name="hints">The table hints to be used. This argument will only be used if the 'isReturnIdentity' argument is 'true'.</param>
        /// <param name="batchSize">The size per batch to be used.</param>
        /// <param name="isReturnIdentity">The flags that signify whether the identity values will be returned.</param>
        /// <param name="usePhysicalPseudoTempTable">The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <returns>The number of rows affected by the execution.</returns>
        public static int BulkInsert <TEntity>(this DbRepository <SqlConnection> repository,
                                               string tableName,
                                               IEnumerable <TEntity> entities,
                                               IEnumerable <BulkInsertMapItem> mappings = null,
                                               SqlBulkCopyOptions?options = null,
                                               string hints                    = null,
                                               int?batchSize                   = null,
                                               bool?isReturnIdentity           = null,
                                               bool?usePhysicalPseudoTempTable = null,
                                               SqlTransaction transaction      = null)
            where TEntity : class
        {
            // Create a connection
            using var bulkDbConnector = new BulkDbConnector(transaction, repository);

            // Call the method
            return(bulkDbConnector.Connection.BulkInsert(tableName: tableName,
                                                         entities: entities,
                                                         mappings: mappings,
                                                         options: options,
                                                         hints: hints,
                                                         bulkCopyTimeout: repository.CommandTimeout,
                                                         batchSize: batchSize,
                                                         isReturnIdentity: isReturnIdentity,
                                                         usePhysicalPseudoTempTable: usePhysicalPseudoTempTable,
                                                         transaction: transaction));
        }
Esempio n. 6
0
        /// <summary>
        /// Bulk insert an instance of <see cref="DbDataReader"/> object into the database.
        /// </summary>
        /// <typeparam name="TEntity">The type of the data entity object.</typeparam>
        /// <param name="repository">The instance of <see cref="DbRepository{TDbConnection}"/> object.</param>
        /// <param name="reader">The <see cref="DbDataReader"/> object to be used in the bulk-insert operation.</param>
        /// <param name="mappings">The list of the columns to be used for mappings. If this parameter is not set, then all columns will be used for mapping.</param>
        /// <param name="options">The bulk-copy options to be used.</param>
        /// <param name="batchSize">The size per batch to be used.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <returns>The number of rows affected by the execution.</returns>
        public static int BulkInsert <TEntity>(this DbRepository <SqlConnection> repository,
                                               DbDataReader reader,
                                               IEnumerable <BulkInsertMapItem> mappings = null,
                                               SqlBulkCopyOptions?options = null,
                                               int?batchSize = null,
                                               SqlTransaction transaction = null)
            where TEntity : class
        {
            // Create a connection
            using var bulkDbConnector = new BulkDbConnector(transaction, repository);

            // Call the method
            return(bulkDbConnector.Connection.BulkInsert <TEntity>(reader: reader,
                                                                   mappings: mappings,
                                                                   options: options,
                                                                   bulkCopyTimeout: repository.CommandTimeout,
                                                                   batchSize: batchSize,
                                                                   transaction: transaction));
        }