Vibrant discussion about CSLA .NET and using the framework to build great business applications.
In CSLA 1.1, MarkDirty() is called when a property has changed its value. In CSLA 2.0, PropertyHasChanged() performs 3 actions: a.) it executes the validations rules if there are any b.) calls MarkDirty() and c.) call OnPropertyChanged.
I've watched the CSLA 2.0 Part 2 in DNRTV, it seems in the project trakker sample in the property it calls Validation.CheckRules("PropertyName") and followed by the PropertyHasChanged() method. Isn't it redudant to call CheckRules() in the property when it is already called inside the PropertyHasChanged()?
I dont know if this is a typo error, just want to know the correct way of doing it. Maybe Rocky has a reason why he called the CheckRules("") w/ PropertyHasChanged().
Can you be more specific? Not sure which Object or Property of Project Tracker you are referring to, so what I am about to type may be incorrect. If the property name in Validation.CheckRules("PropertyName") is the same as the property it is being called within then I agree that it is incorrect. However, if the property name is different then this is perfectly valid as it means that the property specified in Validation.CheckRules("PropertyName") has some validation rules that depend on the value of the property it is being called from. Hope that makes sense as it is hard to explain. Basically, PropertyHasChanged uses reflection to determine which property has changed and therefore only checks the rules for that property. So if we have one property that depends on another we have to force it to recheck the rules for the dependent property when the other changes.
I think your right, I guess Rocky ported the project trakker from 1.1 to 2.0 and forget to make the necessary changes in the part. Anyways, its not that big deal but again just making sure what is the right way of doing it.
In my case, I only called PropertyHasChanged() if the validation rules aren't complex. I have a scenario here that the business rule of a property has a computation and it affects other properties.. I explicitly called CheckRules() and MarkDirty() and OnPropertyChanged()
Ooops.. sorry guys.. the project trakker Project.vb is okay. I got blinded with Started() and Ended() Properties in Project.vb .. Your right razorkai. What I mean is the same property name. Apologize for not being specific.. ;-)
Thanks razorkai and aiij????
I think you misread what I was showing.
It is true that ProjectTracker has a couple properties where CheckRules() is called explicitly - but that is against a different property from the one being set. Specifically, the Started and Ended properties in Project do this.
The reason is that these two properties have a co-dependant validation rule (Started<=Ended). In order to get the ErrorProvider to show both properties in error due to the same rule violation, Started must call CheckRules("Ended") and Ended must call CheckRules("Started"). The rules for a given property are not being run twice. Instead, the rules for two different properties are being checked when either one changes.
Thanks Rocky.. apologize for not paying attention in the show...grrhhhh