GetChangeSet ChangeSet、Linq 将以什么顺序应用更改?

发布于 2024-07-20 15:25:45 字数 499 浏览 5 评论 0原文

我正在运行代码以在 linq 提交更改调用之前获取更改集。

private void OnSubmitHandleReplication()
{
    System.Data.Linq.ChangeSet changes = GetChangeSet();
    //Do something with change set
}

在“执行某些操作”部分中,我需要知道提交内容的顺序以及它们将按什么顺序发布到数据库。我看到更改集有 .Inserted、.Updated 和 .Deleted。 我假设这些是按照它们应用的顺序排列的。但是我想知道总体顺序。 我认为它可能是插入、更新,然后是另外 3 个插入,或者涉及在这些集合之间来回反弹的操作。

更新 1

抱歉,我认为标题很清楚,Linq to SQL

更新 2

我这样做的原因是稍后将这些内容重播到另一个数据库。

I am running the code to get the change set just before a linq submit changes call.

private void OnSubmitHandleReplication()
{
    System.Data.Linq.ChangeSet changes = GetChangeSet();
    //Do something with change set
}

In the do something section I need to know what order things were submitted in, and what order they will post to the database in. I see the change set has a .Inserted, .Updated, and .Deleted. I assume that these are in the order they will be applied in. However I want to know the over all order. I assume it could be Insert, Update, then 3 more inserts, or something that involves bounce back and forth between these collections.

Update 1

Sorry, thought the title was clear, Linq to SQL

Update 2

The reason I am doing this is to replay these later to another DB.

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

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

发布评论

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

评论(2

野生奥特曼 2024-07-27 15:25:45

这是相当棘手的。

您需要通过反射深入挖掘更改跟踪器才能获得实际的订单。

关于插入、更新、删除的顺序,插入发生在删除之前,因此您需要注意唯一约束(这可能意味着您需要更新而不是重新创建)。

编辑

如果您只需要“重播”,那么您当然可以使用日志记录功能。

This is quite tricky.

You would need to dig quite far into the change tracker with reflection to get the actual order.

Regarding the order of insert, update, delete, inserts happen before delete, so you need to watch out for unique constraints (which probably means you needed to update instead of recreate).

EDIT

If you just need to 'replay', surely you could use the logging feature.

舟遥客 2024-07-27 15:25:45

您可以通过设置 YourDataContext.Log = Console.Out 或任何其他兼容的输出流来启用 Linq2SQL 中的日志记录。
LINQ 发送到数据库的每个 SQL 查询都将在那里打印。 您应该只使用它来调试您的问题,因为 LINQ 发送相当多的查询:)

编辑:关于操作的顺序,我无法进一步帮助您,我从来没有比我必须的更多地查看这些查询。

You can enable logging in Linq2SQL by setting YourDataContext.Log = Console.Out or to any other compatible output stream.
Every SQL query LINQ is sending to the database will be printed there. You should only use this for debugging your problem, because LINQ sends quite a lot of queries :)

Edit: Regarding the order of the actions, I cannot help you any further, I never looked at these queries more than I had to.

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