1

How do I delete multiple entities without a loop? Currently, I have:

 Dim itemsToDelete As List(Of Item) = (From t In _entities.Item _
                                            Where t.Column = columnValue).ToList

 For Each item In itemsToDelete
      _entities.DeleteObject(item)
 Next

 _entities.SaveChanges()
Moderator71
  • 385
  • 7
  • 16
  • 2
    possible duplicate of [Bulk-deleting in LINQ to Entities](http://stackoverflow.com/questions/869209/bulk-deleting-in-linq-to-entities) – Craig Stuntz Oct 12 '10 at 20:55
  • Interesting, an extension method would do the job, but I was hoping to find something already built into the EF. – Moderator71 Oct 12 '10 at 21:47

1 Answers1

3

One word: DON'T !

Any of the typical ORM's - be it Linq-to-SQL, NHibernate, Entit Framework and any other - are great at handling single or a few objects.

There are not however designed or optimized for bulk handling.

If you need to delete hundreds or thousands of rows: use straight SQL - either as an ad-hoc SQL query, or as a stored procedure. It's much easier and much more efficient to do it that way.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459