开发者

How to perform a bulk delete with the Entity Framework?

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

 Dim itemsToDelete A开发者_运维知识库s List(Of Item) = (From t In _entities.Item _
                                            Where t.Column = columnValue).ToList

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

 _entities.SaveChanges()


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜