Dynamics CRM 插件和 Web 服务中的交易

Transactions in Dynamics CRM Plugin and Web Services

我想确认我对在 Dynamics CRM 中管理交易的理解,并检查我是否遗漏了什么。

1) CRM 插件中的交易: 在数据库事务下的事件管道 运行 的阶段 20 和 40 中注册的插件。因此,如果我在任何消息的 pre/post 操作上注册了三个插件,并且如果第三个插件抛出异常,则前两个插件所做的更改也将回滚。这个理解对吗?

2) CRM Web 服务中的交易: 如果使用 CRM Web 服务编写代码,我可以使用 ExecuteTransactionRequest 请求,并且随此消息提供的所有请求消息将在一个 CRM 数据库事务下 运行。此消息似乎是在 2016 版中引入的,那么在 2016 年之前处理此类情况的理想方法是什么?

1) 假设插件全部 运行 同步,那么是的,所有更改都应该回滚。

Inclusion in database transactions

Plug-ins may or may not execute within the database transaction of the Microsoft Dynamics CRM platform. Whether a plug-in is part of the transaction is dependent on how the message request is processed by the pipeline. You can check if the plug-in is executing in-transaction by reading the IsInTransaction property inherited by IPluginExecutionContext that is passed to the plug-in. If a plug-in is executing in the database transaction and allows an exception to be passed back to the platform, the entire transaction will be rolled back. Stages 20 and 40 are guaranteed to be part of the database transaction while stage 10 may be part of the transaction.

Any registered plug-in that executes during the database transaction and that passes an exception back to the platform cancels the core operation. This results in a rollback of the core operation. In addition, any pre-event or post event registered plug-ins that have not yet executed and any workflow that is triggered by the same event that the plug-in was registered for will not execute.

2)

  • 是的,ExecuteTransactionRequest 是 CRM 2016 的一项新功能。
  • 如果您有 CRM 2013+,您可以将逻辑放在支持自动回滚的 Action 中。然后用输入调用动作。
  • 对于 CRM 2011,将逻辑放在插件中。然后触发插件,例如通过在 CRM 中创建记录。您还可以捕获新记录的输入。