Skip to main content
Version: Next

Batch Operations

Files Referenced in this Document

  • IMyEntityNameAppService.cs
  • MyEntityNameAppService.cs

Table of Contents​

  1. Introduction
  2. Batch Deletion (DeleteManyAsync)
  3. Implementation Details
  4. Performance Considerations
  5. 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:

  1. Accepts a List<Guid> containing the IDs of entities to delete.
  2. Validates that the list is not empty.
  3. Calls the repository's DeleteManyAsync method.
  4. 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 DELETE calls.
  • 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 DeleteManyAsync handles 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