If a BO has large set of properties/fields

If a BO has large set of properties/fields

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


k2so posted on Wednesday, June 04, 2008

Assuming it is inheriting from BusinessBase class

1. What are some suggestions in making the class more manageable through CSLA?
2. There is a long list of validation rules, how may I (if possible) shorten it; can a rule be applied to more than one property without writing another line of code for each property?

Appreciate any comments on this~ cheers Smile [:)]

JoeFallon1 replied on Thursday, June 05, 2008

Any rule which is "common" to various properties should be re-factored into a "common rules" class just like Rocky ships with CSLA. In fact I basically copied those rules (so I could also tweak them without editing CSLA itself) and then added more of my own. Now the rules are centralized and I can apply them to many BOs and many properties. In fact, I code gen most of the rules.

For a given BO it may have some rules which are specific to it. In those cases I use the strongly typed rule methods and write the rule in the BO itself. I then have access to all the member variables of the BO.

Finally there is AddDependentProperty which allows you to run the rules for another property if the first property is modified.

Joe

k2so replied on Thursday, June 05, 2008

Thanks! That's very helpful~

one quick little thing

AddDependentProperty -
I am confused with which param is which, can sm1 explain a little?

and should this be added into the validation rules section?

JoeFallon1 replied on Thursday, June 05, 2008

Yes. It is added to the Validation rules section, AddBusinessRules.

'when property1 is changed re-check the rules for Property2 and vice versa.
ValidationRules.AddDependantProperty("Property1", "Property2", True)

'when property1 is changed re-check the rules for Property2 but NOT vice versa.
ValidationRules.AddDependantProperty("Property1", "Property2", False)

 

There is a spelling change in CSLA 3.5 from AddDependantProperty to AddDependentProperty. So use the "wrong" spelling in earlier versions and make the change once you upgrade to 3.5 You will get a compiler warning anyway about the old spelling being deprecated.

Joe

k2so replied on Friday, June 06, 2008

Thanks!

Copyright (c) Marimer LLC