We are working with CSLA 4.2 and we have an issue with the business rules.we set business Rules (for example default value for Date property)
protected override void AddBusinessRules()
Date = DateTime.Now;
when we create new business object like:
BL.DailyFlight df = BL.DailyFlight.New();
the date property set correctly in first time (DateTime.Now) but once create another instance from same Business object the date property not set to (DateTime.Now).
how we can resolve this issue?
Do NOT set default values in AddBusinessRules. This method should ONLY be used to define the business rules for the type.
Business Rules is defined per type so AddBusinessRules is only called the first time an object of this type is created. (Hence you only get the value in the first object). IE: AddBusinessRules is only for registering rules for a type - not for execution of rules.
You should set default values in DataPortal_Create or the object factory Create method, depending on your choice of Data Access.
Default values will also be set the first time your code get a value from an "non-initialized" field or when a rule is called on that field.
BusinessRules will run when you call BusinessRules.CheckRules or (after the object is databound) - <bo>.PropertyHasChanged or <bo>.CheckObjectRules.
Many thanks Jonny
Copyright (c) Marimer LLC