Batch Operations
Files Referenced in this Document
IMyEntityNameAppService.csMyEntityNameAppService.cs
Table of Contents
- Introduction
- Batch Deletion (DeleteManyAsync)
- Implementation Details
- Performance Considerations
- Usage Example
Introduction
Batch operations allow processing multiple entities in a single API call, significantly reducing network overhead and improving system responsiveness. The MyEntityNameAppService currently supports batch deletion, which is essential for managing lists of data in administrative interfaces.
Batch Deletion (DeleteManyAsync)
Method Signature: Task DeleteManyAsync(List<Guid> ids)
Description: Accepts a list of entity IDs and deletes them from the database in a single operation.
Process:
- Accepts a
List<Guid>containing the IDs of entities to delete. - Validates that the list is not empty.
- Calls the repository's
DeleteManyAsyncmethod. - Returns success upon completion.
Implementation Details
The implementation in MyEntityNameAppService delegates the logic to the underlying repository, which leverages Entity Framework Core's batch capabilities (or ABP's optimized batch deletion logic) to generate efficient SQL.
public async Task DeleteManyAsync(List<Guid> ids)
{
await Repository.DeleteManyAsync(ids);
}
This approach ensures that deletions are handled within a transaction (if configured) and respects soft-delete filters if applicable.
Performance Considerations
- Network Efficiency: One HTTP request replaces multiple
DELETEcalls. - Database Efficiency: Reduced number of database roundtrips and transaction overhead.
- Batch Size: For extremely large batches (e.g., thousands), consider splitting them into smaller chunks to avoid timeouts or locking issues, although
DeleteManyAsynchandles typical UI-driven batch sizes (tens to hundreds) efficiently.
Usage Example
Request:
POST /api/app/my-entity-name/delete-many
[
"3a0d636e-530b-4a57-8148-1234567890ab",
"2b1c525d-420a-3b46-7037-0987654321cd"
]
Response:
204 No Content