8

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.

Adan
  • 95
  • 1
  • 1
  • 4

2 Answers2

3

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)

Community
  • 1
  • 1
itchi
  • 1,683
  • 14
  • 30
-2

I know this post is kinda of old, but a code example would be the following:

foreach(var item in items) { context.Remove(item); }

  • Yes you say that, but using pure Entity Framework, it is the way that it has to be done unless you push an actual query to the DB. – Ramone Hamilton May 18 '13 at 04:57
  • Yeah, but if you would've read the question you would've seen: "Is there a better way than to loop trough the list?" – Tincan Aug 05 '14 at 11:32