DELETE all entities from the database.
All rows that match the entity key are
DELETED from the database.
Deleting entities using a custom key from file importation is a typical scenario.
ChangeTracker being outstanding to track what’s modified, it lacks in term of scalability and flexibility.
SaveChanges requires one database round-trip for every entity to
delete. So if you need to
delete 10000 entities, then 10000 database round-trips will be performed which is INSANELY slow.
BulkDelete in counterpart offers great customization and requires the minimum database round-trips as possible.
|Operations||1,000 Entities||2,000 Entities||5,000 Entities|
|SaveChanges||1,000 ms||2,000 ms||5,000 ms|
|BulkDelete||45 ms||50 ms||60 ms|
You can specify more than one option using anonymous block.
You can specify a custom batch size using the
Read more: BatchSize
You can specify custom key using the
Read more: ColumnPrimaryKeyExpression
You cannot. Due to the risk of mistakes, we preferred not to offer this option and make sure every entity you wish to
delete is specified.
To provide the best performance possible!
Since using the
ChangeTracker can greatly reduce performance, we chose to let
BulkSaveChanges method handle scenarios with
BulkDelete, scenarios without it.
The major difference between both methods is
BulkSaveChanges uses the
ChangeTracker but not the
By skipping the
ChangeTracker, some methods like
DetectChanges are no longer required which greatly helps to improve the performance.