Linq SubmitChanges() 函数 - 何时调用?

发布于 2024-09-16 19:43:38 字数 291 浏览 5 评论 0原文

使用 Linq 操作数据时,必须多久调用一次 SubmitChanges() 方法?

在我的项目中,有一些与外键相关的表。在创建 SQL 中,这些外键受到约束,因此如果不首先删除相关记录,则无法删除属于关系的记录。

因此,需要删除关系内的记录有一个特定的顺序。我是否必须删除每条记录,并每次对数据库执行 SubmitChanges() 函数,或者我可以一次性执行所有删除吗?

编辑:我的主要问题是:在 SubmitChanges() 上删除记录的顺序是否与在代码中删除记录的顺序相同?

When manipulating data using Linq, how often does the SubmitChanges() method have to be called?

In my project, there are a few tables related with foreign keys. In the creation SQL, these foreign keys are constrained so a record that is part of a relationship can't be deleted without the dependant records being deleted first.

Therefore, there is a specific order that records within a relation need to be deleted. Will I have to delete each record, and perform a SubmitChanges() function on the database each time, or can I perform all the deletes in one go?

EDIT: My main question is: Do the records get deleted on SubmitChanges() in the same order as you delete them in code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧瑾黎汐 2024-09-23 19:43:38

您应该尝试尽可能少地调用它,但是当您进行有效替换实体的插入和删除操作时,Linq2SQL 存在一个已知问题。在这些情况下,最好在删除和后续插入后尽快调用它。

这是一个类似的问题我问了一个回来的时候。

You should try call it as little as possible, but there is a known issue with Linq2SQL when you have insert and deletes that is effectively replacing an entity. In those cases, it is best to call it as soon as possible after the delete and subsequent insert.

Here is a similar question I asked a while back.

梦里的微风 2024-09-23 19:43:38

如果您需要批量删除(例如单个事务),则应仅在标记所有要删除的对象后调用 SubmitChanges 方法一次。

If you need to delete as a batch e.g. a single transaction, you should only call the SubmitChanges method once when you have marked all the objects to be deleted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文