Validator classes issue

Posts   
 
    
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 10-Sep-2006 11:14:03   

Hi

I am trying to upgrade my application to v2.0 from v1.2005 and I have a problem with validator classes.

In v1.2005 I generated a set of manager classes in a project I called SABER.Engine.BusinessObjects

As part of these manager classes I generated a set of validator classes (one for each entity) I.E. namespace SABER.Engine.BusinessObjects.ValidatorClasses.

I then used EntityValidatorToUse method to set the relevant validator and everything worked fine.

Under V2.0 I have a problem

EntityValidatorToUse is obsolete, as per the user manual I now need to use an include template to add a CreateValidate method to my EntityClasses as per the user guide


// C#
/// <summary>
/// Creates the validator object for this entity. Routine is called from the entity constructor. Implem
ent in an entity
/// class to set a particular entity validator object at construction time.
/// </summary>
/// <returns>New validator instance for this entity</returns>
protected override IValidator CreateValidator()
{
return new SABER.Engine.BusinessObjects.ValidatorClasses.CustomerValidator();
}

But of course if I do this I get circular reference problems because my BusinessObjects namespace relies on DBGeneric and DBGeneric relies on BusinessObjects.

The alternative approach (per the user guide) is to turn on the LLBL validator class and put my validation code into that class instead, however I have the same issue because my validator code itself relies on the BusinessObject namespace but when I try to reference in the BusinessObjects project I get circular errors.

Is there a way around this problem?

Many thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Sep-2006 07:42:03   

Under V2.0 I have a problem EntityValidatorToUse is obsolete, as per the user manual I now need to use an include template to add a CreateValidate method to my EntityClasses as per the user guide

In v.2 you can still create your own validator classes and use entity.Validator to attach an instance of the validator class to the entity.

Please consult the LLBLGen Pro v.2 manual "Using the generated code -> Validation per field or per entity"

Check the paragraph titled "Validation logic inside validator classes"

The following lines are copied from the manual:

Creating your validation class is straight forward: derive a class from ValidatorBase and override one or more methods to add your own code to the validation process, similar to overriding the methods in the entity class. You can also set an entity's validator after the entity's created, by setting it's Validator property to an instance of a validator class which derives from ValidatorBase.

hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 11-Sep-2006 16:08:20   

Many thanks entity.Validator will solve my problem. I assume this does exactly what entity.EntityValidatorToUse did under v1.2005

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 11-Sep-2006 16:36:29   

I think you get some more capabilities than in the earlier versions.

Here are the methods that you can use to perform fine grain validation.

        bool ValidateFieldValue(IEntityCore involvedEntity, int fieldIndex, 
        void ValidateEntityAfterLoad( IEntityCore involvedEntity );
        void ValidateEntityBeforeSave( IEntityCore involvedEntity );
        void ValidateEntityAfterSave( IEntityCore involvedEntity );
        void ValidateEntityBeforeDelete( IEntityCore involvedEntity );
        void ValidateEntity( IEntityCore involvedEntity );
        void UnassignedFromEntity( IEntityCore involvedEntity );

Also, you can set the validator in the corresponding constructor rather than setting the property after instanciation.