abp vnext 批量操作 InsertManyAsync UpdateManyAsync等方法源码 电脑版发表于:2023/2/23 21:30 #### InsertManyAsync 方法源码 ``` public override async Task InsertManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default) { var entityArray = entities.ToArray(); var dbContext = await GetDbContextAsync(); cancellationToken = GetCancellationToken(cancellationToken); foreach (var entity in entityArray) { CheckAndSetId(entity); } if (BulkOperationProvider != null) { await BulkOperationProvider.InsertManyAsync<TDbContext, TEntity>( this, entityArray, autoSave, GetCancellationToken(cancellationToken) ); return; } await dbContext.Set<TEntity>().AddRangeAsync(entityArray, cancellationToken); if (autoSave) { await dbContext.SaveChangesAsync(cancellationToken); } } ``` #### UpdateManyAsync 方法源码 ``` public override async Task UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); if (BulkOperationProvider != null) { await BulkOperationProvider.UpdateManyAsync<TDbContext, TEntity>( this, entities, autoSave, GetCancellationToken(cancellationToken) ); return; } var dbContext = await GetDbContextAsync(); dbContext.Set<TEntity>().UpdateRange(entities); if (autoSave) { await dbContext.SaveChangesAsync(cancellationToken); } } ``` 原文地址:https://www.cnblogs.com/liuxiaoji/p/16812874.html