I have an object which is definately not valid (e.g. a property has exceeded its max length). If I inspect the IsValid property, I get back true. If I call ApplyEdit() I still get back true. Now if I call the CheckRules() method for that object, IsValid is false.
I have been good and have a custom BusinessBase class in which I will simply override IsValid and call CheckRules() prior to base.IsValid but it seems somehow weird that this is not the current behaviour...
So could someone please point out if I am missing something out or am doing something wrong? Also, will severity levels mix anything up (when I start using them that is...)?
FYI I am using CSLA 2.1.4
It sounds like you are not having your business rule triggered when your string changes and becomes invalid. Ensure that your PropertyHasChanged() method is getting fired in your string property's setter and ensure that your business rule is hooked up to the property correctly. The moment your string changes in the business object you should be triggering your validation rule... You'd be getting IsValid to flip to false when you do CheckRules because you're essentially firing all of your business rules off.
That's what I'd suggest based on what you wrote above... throw a breakpoint in your validation rule, and hop into your UI and change your control tied to the string property - if your validation rule doesn't fire, then there's a problem.
Chris
Thanks for that. Actually based on your reply let me be more specific (sorry am a bit tired...). The problem is I have a Customer editable root object containing an Orders editable list object. Its one of the Orders that is not valid.
For that Orders object I am calling the PropertyHasChanged in the property in question and in the Customer.IsValid override I do check on both base.IsValid and Orders.IsValid.
Is it possible that when adding an Order in the Customer.OrderList that is not valid (not even sure that's possible) that Customer won't reflect that in its own IsValid?
triplea:For that Orders object I am calling the PropertyHasChanged in the property in question and in the Customer.IsValid override I do check on both base.IsValid and Orders.IsValid.
Thanks Rocky but I was doing that already...
Are you saying it should be invalid when it is new, but it showing valid. Or is it showing valid after the property has been set during use?
For new objects, you would of course call validationRules.checkrules in dataportal_create.
In the property you would call PropertyHasChanged.
I don't know that calling apply edit should have any effect on the valid state, though cancel edit would
Heath
Heath
The object is not new and thanks for reminding me that I should call CheckRules() in the dataportal_create method (was not doing it but added it and the object is valid at creation). I am convinced I somewhere missed something but still think that it would make sense if CheckRules was fired automatically from within IsValid...
I would have to agree with Chris that the problem must be in making sure that you PropertyHasChanged is being called and that the correct authorization rule is giving you the valid/invalid result you expect.
As for whether the child list is not reflecting the state of all its children, that is not a problem. If any children are invalid then the list WILL be invalid.
Heath
Copyright (c) Marimer LLC