Rule priorities not working

Rule priorities not working

Old forum URL: forums.lhotka.net/forums/t/11625.aspx


correodemarques posted on Thursday, October 04, 2012

I have a child object with a some rules and some have to run before others. This one have to run first:

BusinessRules.AddRule<ClientPurchaseOrderLineItem>(ClientBusinessIdProperty, o =>

{

var info = Business.GetInfo(o.ClientBusinessId);

if (info != null)

{

o.LoadClodBusinessId(info.Id);

o.BusinessName = info.Name;

}

else

{

o.LoadClodBusinessId(Guid.Empty);

o.BusinessName = "";

}

 

return info != null;

},

ClientPurchaseOrderLineItemResources.InvalidBusiness);

 

And this one later:

 

BusinessRules.AddRule(new UniqueClientPurchaseOrderLineItemIdRule(PoLineItemIdProperty, ClodBusinessIdProperty) { Priority = 1 });

 

That is why I set the priority to 1, but I set some breakpoints and this last rule always run before the other. What am I doing wrong?

JonnyBee replied on Thursday, October 04, 2012

PropertyRules is run in the context of a Property that has been changed.

IE: The Priority is only applicable within a Property. Then rules for Affected propeties is checked (and agein on a Per-Property basis). 

correodemarques replied on Thursday, October 04, 2012

Hi Jonny,

Thanks for your answer. If I understood correctly that means that the priority is only applied to rules associated with the same property?

 

How can I force one rule to run before the other if they are not related to the same property?

JonnyBee replied on Thursday, October 04, 2012

Yes, prioritiy is only applied to rules for the same property.

You can't force one rule to run before the others when they are not related to the same property. 

You should keep a mindset of :

 

 

Copyright (c) Marimer LLC