Dynamics CRM插件事务处理机制及场景问询
First, let's correct a critical misunderstanding in your initial assumption: Entity B's asynchronous Post Operation does NOT run in the same transaction as Entity A's synchronous Post Operation. Async plugins are queued to execute after the original transaction has fully committed, in a separate, independent context.
Q1: If Entity B's async Post Operation fails, does the entire transaction rollback (including Entity A's changes)?
No, it won't. Here's the step-by-step flow:
- Entity A's synchronous Post Operation is part of the original transaction (e.g., the Create/Update action on Entity A). When this plugin updates Entity B, that Update operation runs synchronously within the same original transaction.
- Any synchronous plugins tied to Entity B's Update (Pre Operation, Post Operation sync) will execute inside this transaction—if any of those fail, the entire transaction rolls back, undoing both Entity A's changes and the Entity B update.
- However, Entity B's async Post Operation is only added to the async queue after the original transaction succeeds and commits. If this async plugin later throws an error, it has no impact on the already saved changes to Entity A or Entity B. The failure will just be logged in the system job history, and you can troubleshoot/retry the async job independently.
Q2: When Entity A's sync plugin updates Entity B, does Entity B's Pre Validation step get skipped?
No, it won't be skipped. Pre Validation runs for every instance of the target operation (Update on Entity B), regardless of whether the operation is triggered by a user, workflow, or another plugin. This stage executes outside the transaction for the Update operation, and it runs before any other plugins for that action. The only scenarios where it wouldn't run are if:
- The plugin registration includes filtering attributes that aren't being modified in this Update request, or
- The plugin is disabled in the plugin registration tool.
内容的提问来源于stack exchange,提问作者jaden behr

