How to - Validation

How to - Validation

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


tna55 posted on Sunday, April 01, 2007

Hi everyone,

I am new to CSLA and still learning the basics. With validation in CSLA.NET we write something like this in property procedures for a Business Object

BrokenRules.Assert("Name","Name Required", Len(value)=0)

This works great. However, how can we do validate one property against the other. For instance if I want to check Gender with DateOfBirth i.e. If both are missing then the Business Object should be invalid. How and where can we do such validations?

Help much appreciated

Tahir

SonOfPirate replied on Sunday, April 01, 2007

Here is a long discussion on this very subject:

http://forums.lhotka.net/forums/thread/8470.aspx

 

tna55 replied on Sunday, April 01, 2007

Hi,

It was helpful thanks. However, it does not discuss (may be directly) the issue I have.

May be you can clarify. I have two properties in BO. Before saving them I need to validate one against the other. Within the property procedure of each, I can't put that. Why? Because unless user presses 'Save' button that rule should not be invoked.

Tahir

Bayu replied on Monday, April 02, 2007

Hi,

If you follow the standard pattern each of your property-set routines invokes PropertyHasChanged() (or PropertyHasChanged(someName)). If you track this call you will see that this maintains the valid-state of your BO.

Also, in the base classes in Csla the Save routine checks the validity before actually committing the change. If the BO is not in a valid state an exception is thrown.

In the ProjectTracker sample you can find examples of BOs that make use of validation and also on One  Little Victory you can find more info.

Bayu

SonOfPirate replied on Monday, April 02, 2007

I am assuming that you are doing something along the lines of a StartDate/EndDate scenario where the EndDate value has to be greater than the StartDate in order to be valid.  You can find an example of how to do this in the ProjectTracker sample app (check the latest version).

HTH

 

Copyright (c) Marimer LLC