Priority-based Execution of RuleSets

As mentioned previously, if you want a certain execution sequence for the RuleSet or a subset of rules in that RuleSet, you can precisely define this sequence by using the priority field on a rule. Doing this frequently removes the requirement for chaining, and you can even turn off the chaining in these scenarios.

Notice that the forward execution mechanism in Windows Workflow Foundation enables you to define an execution sequence, but it does not require that you do so. Most of the time, the forward chaining behavior makes the assignment of rule priorities unnecessary to achieve the correct RuleSet result, because relationships are automatically managed by the engine to make sure that rule dependencies are met.

The following example illustrates this point.

Rule 1
IF this.Weather.Temperature < 50
THEN this.Drink.Style = "Latte"

Rule 2
IF this.Drink.Style == "Latte"
THEN this.Snack.Style = "Scone"
ELSE this.Snack.Style = "Muffin"

In Windows Workflow Foundation, you can provide a higher priority on Rule 1 so that it executes first. This guarantees that Drink.Style is set before Rule 2 is evaluated.

Sequencing is not required, however, to get the results that you want. Assume that Rule 2 is evaluated first. In this case, Drink.Style may be null or could be another style. This would result in the Snack.Style being set to "Muffin". However, after Rule 1 executes and sets Drink.Style to "Latte", Rule 2 would be reevaluated and would set Snack.Style to "Scone". Essentially, you have the option of dictating sequencing, but in many cases do not have to do this.

Sequencing can also be valuable if the rules have dependencies, but you do not want to use explicit Update statements or method attributing for scenarios where they would otherwise be required.

See Also

Reference

RuleSet
RuleUpdateAction

Concepts

Using RuleSets in Workflows
Rules Evaluation in RuleSets