views:

25

answers:

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()
+1  A: 

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