When I create a new BO that inherits from BusinessBase my new BO starts off with IsDirty as true.
Why would a new instance of a BO start off dirty?
It's quite simple really - an object IsDirty if it's values/properties do not match a value in the database/datastore.
Since a new object does not yet exist in the datastore this implies that it IsDirty.
Easy, eh?
HTH
ChrisD
I guess my real problem is that the IsSavable is starting off as True because both IsDirty and IsValid is starting off as true. I have the following rule code and I was expecting IsValid to be false at start because I have StringRequired for "CODE" and the code property is empty at start. How can I tell why is is starting with IsValid true when I think it should be false?
Thanks for your help.
Private Sub AddCommonRules()
ValidationRules.AddRule(AddressOf Validation.CommonRules.StringRequired, "CODE")
ValidationRules.AddRule(AddressOf Validation.CommonRules.StringMaxLength, New Validation.CommonRules.MaxLengthRuleArgs("CODE", 10))
I see that ValidationRules.CheckRules is being called from PropertyHasChanged in BusinessBase but I don't see it being called from DataPortal.Create. So after I create a new BO that has a Code property which is required I get the following results.
Dim cust As Customer = Customer.NewCustomer
' IsValid is True which is wrong since Code is required
cust.Code = "A"
' IsValid is Still True which now is ok as far as Code is concerned.
cust.Code = ""
' IsValid is now False, which is accurate since Code is required.
So modifying the property to trigger the PropertyHasChanged event will cause IsValid to initialize but is there a better way to do this. Are you saying I should modify the CSLA code to call CheckRules in the DataPortal.Create, if so where exactly is that done.
Thanks
You implement DataPortal_Create in your business object and call ValidationRules.CheckRules() from there. You don't have to modify CSLA itself. Here's an example from Rocky's ProjectTracker sample (Project class)...
[RunLocal()]
private void DataPortal_Create(Criteria criteria)
{
_id = Guid.NewGuid();
_started.Date = DateTime.Today;
ValidationRules.CheckRules();
}
Thanks Mark that was it. My DataPortal_Create was empty.
When I created this BO I made the wrong assumption that since I was not intializing any of the properties that the ValidationRules.CheckRules call was not needed.
I think I did that because the example Resources.vb shows DataPortal_Create empty like this:
<RunLocal()> _
Private Overloads Sub DataPortal_Create(ByVal criteria As Criteria) ' nothing to initialize End SubDoes this mean Resource.vb DataPortal_Create is wrong or is the call to CheckRules not needed there for some reason?
Copyright (c) Marimer LLC