diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index b881c07245..325ba8345d 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -126,6 +126,11 @@ public class EfCoreRepository : RepositoryBase, IE { CheckReadOnly(); var entityArray = entities.ToArray(); + if (entityArray.IsNullOrEmpty()) + { + return; + } + var dbContext = await GetDbContextAsync(); cancellationToken = GetCancellationToken(cancellationToken); @@ -172,14 +177,21 @@ public class EfCoreRepository : RepositoryBase, IE public async override Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) { + var entityArray = entities.ToArray(); + if (entityArray.IsNullOrEmpty()) + { + return; + } + CheckReadOnly(); + cancellationToken = GetCancellationToken(cancellationToken); if (BulkOperationProvider != null) { await BulkOperationProvider.UpdateManyAsync( this, - entities, + entityArray, autoSave, GetCancellationToken(cancellationToken) ); @@ -189,7 +201,7 @@ public class EfCoreRepository : RepositoryBase, IE var dbContext = await GetDbContextAsync(); - dbContext.Set().UpdateRange(entities); + dbContext.Set().UpdateRange(entityArray); if (autoSave) { @@ -212,6 +224,12 @@ public class EfCoreRepository : RepositoryBase, IE public async override Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) { + var entityArray = entities.ToArray(); + if (entityArray.IsNullOrEmpty()) + { + return; + } + CheckReadOnly(); cancellationToken = GetCancellationToken(cancellationToken); @@ -219,7 +237,7 @@ public class EfCoreRepository : RepositoryBase, IE { await BulkOperationProvider.DeleteManyAsync( this, - entities, + entityArray, autoSave, cancellationToken ); @@ -229,7 +247,7 @@ public class EfCoreRepository : RepositoryBase, IE var dbContext = await GetDbContextAsync(); - dbContext.RemoveRange(entities); + dbContext.RemoveRange(entityArray.Select(x => x)); if (autoSave) { diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 58f5c72716..4ebe61f64e 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -138,9 +138,13 @@ public class MongoDbRepository public async override Task InsertManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) { - cancellationToken = GetCancellationToken(cancellationToken); - var entityArray = entities.ToArray(); + if (entityArray.IsNullOrEmpty()) + { + return; + } + + cancellationToken = GetCancellationToken(cancellationToken); foreach (var entity in entityArray) { @@ -228,6 +232,10 @@ public class MongoDbRepository public async override Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) { var entityArray = entities.ToArray(); + if (entityArray.IsNullOrEmpty()) + { + return; + } foreach (var entity in entityArray) { @@ -358,12 +366,18 @@ public class MongoDbRepository bool autoSave = false, CancellationToken cancellationToken = default) { + var entityArray = entities.ToArray(); + if (entityArray.IsNullOrEmpty()) + { + return; + } + cancellationToken = GetCancellationToken(cancellationToken); var softDeletedEntities = new Dictionary(); var hardDeletedEntities = new List(); - foreach (var entity in entities) + foreach (var entity in entityArray) { if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity)) { @@ -383,7 +397,7 @@ public class MongoDbRepository if (BulkOperationProvider != null) { - await BulkOperationProvider.DeleteManyAsync(this, entities, dbContext.SessionHandle, autoSave, cancellationToken); + await BulkOperationProvider.DeleteManyAsync(this, entityArray, dbContext.SessionHandle, autoSave, cancellationToken); return; }