Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entities Framework 4 doing a bulk delete

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.

like image 842
Adan Avatar asked Apr 06 '10 22:04

Adan


People also ask

How do I delete all records in Entity Framework?

Table select o; foreach (var row in rows) { dataDb. Table. Remove(row); } dataDb. SaveChanges();

How do I Soft delete in Entity Framework?

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.

What is bulk delete?

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.


1 Answers

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)

like image 73
itchi Avatar answered Sep 29 '22 19:09

itchi