Dynamic CRM 2013 插件管道阶段和数据库回滚

Dynamic CRM 2013 Plugin pipeline stage and database rollback

我在同一管道阶段(post 操作)注册了 2 个插件,并在同一实体 实体 A(创建事件)上触发。

当插件 1 在 实体 A 上触发(创建事件)并更改 实体 B 并且另一个插件 2 在 实体 A(创建事件)并且在对 实体 A 进行更改时抛出异常。

插件 1 对 实体 B 所做的更改是否被回滚,因为两个插件在同一实体上触发并且它们具有相同的管道阶段或插件 1 对实体 B 所做的更改实体 B 保留并且不会被回滚?

取决于插件交易。

Event execution pipeline

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 (pre-operation) 20 and (post-operation) 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 的异常将冒泡到插件 1。如果两个插件都在一个事务中,则两个插件的操作都会回滚。