Overview
Bulk operations significantly improve performance when working with large datasets by reducing the number of database round trips. This module adds extension methods to repositories for:- Bulk Insert
- Bulk Update
- Bulk Delete
- Bulk Insert or Update (Upsert)
- Bulk Read
Installation
Benefits
Compared to standard EF Core operations:- 10-50x faster for inserts
- 5-25x faster for updates
- 3-15x faster for deletes
- Reduced memory consumption
- Optimal for batch processing
Usage
Bulk Insert
Bulk Insert
Bulk Update
Bulk Update
Bulk Delete
Bulk Delete
Bulk Insert or Update (Upsert)
Upsert
Bulk Read
Bulk Read
Configuration Options
Bulk operations can be configured with various options:Configuration
BatchSize
BatchSize
Number of entities processed in each batch.
- Larger batches = fewer round trips but more memory
- Smaller batches = more round trips but less memory
2000BulkCopyTimeout
BulkCopyTimeout
Timeout in seconds for bulk copy operations.Increase for very large datasets.Default:
30PreserveInsertOrder
PreserveInsertOrder
Maintains the order of entities during insert.Useful when insert order matters for foreign key relationships.Default:
trueSetOutputIdentity
SetOutputIdentity
Sets the identity values for inserted entities.When true, generated IDs are populated back into the entity objects.Default:
falseUseTempDB
UseTempDB
Uses temporary database tables for staging.Can improve performance for very large datasets.Default:
falsePerformance Comparison
Standard vs Bulk Insert
Performance Test
Advanced Scenarios
Conditional Upsert
Conditional Upsert
Bulk Delete with Predicate
Bulk Delete with Predicate
Transaction Support
Transaction
Database Provider Support
Bulk operations are supported on:- ✅ SQL Server
- ✅ PostgreSQL
- ✅ MySQL
- ✅ SQLite
- ❌ In-Memory (falls back to standard operations)
- ❌ Cosmos DB (not applicable)
NuGet Dependencies
This module automatically adds:EFCore.BulkExtensions- Core bulk operations library- Database-specific extensions based on your provider
Best Practices
Use for Large Batches
Bulk operations shine with 1,000+ entities. For smaller batches, standard EF Core may be sufficient.
Consider Memory
Loading large datasets into memory can cause issues. Use batch processing for very large operations.
Disable Tracking
Use
AsNoTracking() when querying data for bulk operations to reduce memory overhead.Test Performance
Always benchmark bulk operations in your specific environment with realistic data volumes.
Limitations
- Triggers and computed columns may not fire during bulk operations
- Some database features (like temporal tables) may require special handling
- Identity insert requires explicit configuration
- Navigation properties are not automatically processed
Related Modules
- Entity Framework Core - Base EF Core module
- EF Core Repositories - Repository implementation
