ValidationRules Quirk

ValidationRules Quirk

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


Ian posted on Monday, February 23, 2009

I just discovered something a little quirky with the ValidationRulesin Csla 3.6.0.  My Customer object has a simple validation rule:

protected override void AddBusinessRules()

{

ValidationRules.AddRule(Csla.Validation.CommonRules.StringRequired,new Csla.Validation.RuleArgs(CustomerNameProperty));

}

In my test program I have simply:

Customer customer = Customer.NewCustomer();

customer.CustomerName = "New Customer";  <- put breakpoint here

customer.Phone = "555555";  <- put breakpoint here

Put a breakpoint on both the customer.Phone line and the customer.CustomerName line and run the code.  When execution stops on the CustomerName line, just hit F5 and continue to the Phone line.  With execution stopped at that line, check the IsValid property using intellisense of the Customer object.  IsValid = True, which is to be expected.

Now, restart the code, but this time when execution is on the CustomerName line, check the IsValid property using intellisense.  Note that IsValid = False, which is to be expected since the name property hasn't been set yet.  Hit F5 and continue to the Phone line and check IsValid again.  It's still false even though the name property has a value.  I know that it's not just the intellisense being "out of date" because if you continue to a Save() call, Csla throws an exeception because there is still a broken rule. 

I don't know if it makes a difference, but I'm using private backing fields.

 

Copyright (c) Marimer LLC