I wish to know if there is a good way to do a bulk delete or delete multiple rows using the Entities Framework 4. I can't seam to find a DeleteAll command. The only one that is available is DeleteObject() which only takes one entity, I would like to perform a delete on a list of entities.Is there a better way than to loop trough the list? I did see an article that used ExecuteStoreQuery and created some sql that would perform the delete. Is there a better way than to perform any of these two options Please advice what is the best way to perform this action.
Table select o; foreach (var row in rows) { dataDb. Table. Remove(row); } dataDb. SaveChanges();
The Soft Delete feature allows you to flag entities as deleted (Soft Delete) instead of deleting them physically (Hard Delete). The soft delete feature can be achieved by using the 'IEFSoftDelete' interface. By default, this interface is always added to the manager.
The bulk deletion feature helps you to maintain data quality and manage the consumption of system storage by deleting data that you no longer need. For example, you can delete the following data in bulk: Stale data. Data that is irrelevant to the business.
There isn't an elegant way to do this as of yet. You're correct, you'll have to loop through the list.
This SO post has some good discussions on the topic: How do I delete multiple rows in Entity Framework (without foreach)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With