实体框架4进行批量删除 [英] Entities Framework 4 doing a bulk delete

查看:143
本文介绍了实体框架4进行批量删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个很好的方式使用Entities Framework 4进行批量删除或删除多行。我无法找到一个DeleteAll命令。唯一可用的是DeleteObject(),它只需要一个实体,我想在一个实体列表上执行删除。有更好的方法比通过列表循环吗?我看到一篇使用ExecuteStoreQuery的文章,并创建了一些将执行删除的sql。有没有比执行这两个选项更好的方法请咨询什么是执行此操作的最佳方法。

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.

推荐答案

没有一个优雅的方式来做到这一点。你是正确的,你必须循环浏览这个列表。

There isn't an elegant way to do this as of yet. You're correct, you'll have to loop through the list.

这个帖子对这个主题有一些很好的讨论:
如何在Entity Framework中删除多个行(不用foreach)

This SO post has some good discussions on the topic: How do I delete multiple rows in Entity Framework (without foreach)

这篇关于实体框架4进行批量删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆