How can I have a Validation rule that requires two fields?

How can I have a Validation rule that requires two fields?

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


IraD posted on Friday, March 16, 2007

I need to have a business rule that looks at two fields at once.  For example, FieldA, an integer, must be between 1 and FieldB, which is another property in the same object.

Can anyone show me how to code the rule and the rule args and the AddBusinessRule?

Or just point me at an example somewhere.  Thanks.

RockfordLhotka replied on Friday, March 16, 2007

What you are describing is not much different from the custom rule in the Project class in ProjectTracker. That method compares the start and end dates of the project - but you can use the same scheme to limit one field by the other in different ways.

IraD replied on Friday, March 16, 2007

Are you referring to the BrokenRules.Assert coding? I haven't used that before and will investigate it.

I have simplified my example and am wondering if I have created a distortion.  The real case is that I have a complex edit to perform on FieldA but the value of FieldB must be known to perform the correct test.

Should I stay away from the CommonRules and CustomRules approach and instead code it in the SET for the fields?   

mercule replied on Friday, March 16, 2007

Ira,

The method in question is the StartDateGTEndDate() method in the Project class.

The example is on pp 416-417 of the C# book.

IraD replied on Monday, March 19, 2007

All is belatedly clear. Thanks to Rocky and Mercule.

Copyright (c) Marimer LLC