Click or drag to resize

Validation

In order to understand the validation, it is important to first comprehend that validation occurs in different places, e.g. for different operations.

ValidationState is used to represent the different validation operations that can occur. This includes the most common Insert, Update and Delete, but can also include user-defined operations (for example documents might have different states and each state can have different validations). The validation operation looks and acts like enum. However, it is simply a class and a bunch of derivative classes and thus it can be extended to include new members. It takes some time to understand, but offers great flexibility.

Validations are enforced, using the class ValidationRuleT. This class represents one validation rule, which must be enforced. The rule can be enforced on several operations. For example, it is common to define a rule once, but enforce it for Insert and Update and sometimes for also for Delete. For example, this can be accomplished by placing the following code in the InitializeValidationRules() method of the repository:

ValidationRule<TObject> ghostRule = 
  new LambdaValidationRule<TObject>(o => o.IsGhost == false, "Operation invalid on ghost objects");
AddValidationRule(ghostRule, ValidationOperation.Insert);
AddValidationRule(ghostRule, ValidationOperation.Update);
AddValidationRule(ghostRule, ValidationOperation.Delete);