Exemple #1
0
        public virtual async Task BulkUpdateManyAsync(IList <T> entities)
        {
            if (entities.Count == 0)
            {
                return;
            }

            var strategy = _dbContext.Database.CreateExecutionStrategy();

            await strategy.Execute(async() =>
            {
                await using var transaction = await _dbContext.Database.BeginTransactionAsync();
                try
                {
                    await _dbContext.BulkUpdateAsync(entities,
                                                     config => config.UseTempDB = true);
                    await transaction.CommitAsync();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message, ex.InnerException);
                    await transaction.RollbackAsync();
                    throw;
                }
            });
        }