Calling ValidateEntity()

Posts   
 
    
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 27-Feb-2007 11:38:49   

Hi there,

I have finally managed to start migrating to 2.0, every thing went really smooth! i still have a problem with validation...

i created a base Validator that looks like this


Public Class BFValidatorBase
    Inherits ValidatorBase
    ....
End Class

This class has some validation-routines that apply to a large number of entities.

For a number of entitities i created specialized validators


Public Class ValidatorAuftrag
        Inherits BFValidatorBase
        Public Overrides Sub ValidateEntityBeforeSave(ByVal involvedEntity As IEntityCore)
        End Sub

        Public Overrides Sub ValidateEntity(ByVal involvedEntity As IEntityCore)
        End Sub
End Class

I also have a generalised validation routine on my BL


    Public Function Validate(ByVal Entity As EntityBase2) As ORMEntityValidationException Implements IBusinessFacade.Validate
        Me.SetValidator(Entity, True)
        Try
            Entity.ValidateEntity()
            Entity.Validator.ValidateEntity(Entity)
        Catch ex As ApplicationException
            Return ex
        End Try
    End Function

SetValidator finds the proper validator for an entity and sets it through the accessor Entity.Validator.

The problem is: calling Entity.ValidateEntity() dosen't result in the proper method in the validator being fired. I have to call Entity.Validator.ValidateEntity(Entity). What is really irritiating is that ValidateEntityBeforeSave is being called the way it should be!

What am i doing wrong here?

another issue is the implementation of IDataErrorInfo. Until now i had been collecting error-messages and displaying by searching for the binding element on the form. I am using janus controls on my form, do i need to add extra code in order for these messages to appear for the controls?

Thank you very much in advance for your help

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 27-Feb-2007 20:44:40   

eugene wrote:

Hi there,

I have finally managed to start migrating to 2.0, every thing went really smooth! i still have a problem with validation...

i created a base Validator that looks like this


Public Class BFValidatorBase
    Inherits ValidatorBase
    ....
End Class

This class has some validation-routines that apply to a large number of entities.

For a number of entitities i created specialized validators


Public Class ValidatorAuftrag
        Inherits BFValidatorBase
        Public Overrides Sub ValidateEntityBeforeSave(ByVal involvedEntity As IEntityCore)
        End Sub

        Public Overrides Sub ValidateEntity(ByVal involvedEntity As IEntityCore)
        End Sub
End Class

I also have a generalised validation routine on my BL


    Public Function Validate(ByVal Entity As EntityBase2) As ORMEntityValidationException Implements IBusinessFacade.Validate
        Me.SetValidator(Entity, True)
        Try
            Entity.ValidateEntity()
            Entity.Validator.ValidateEntity(Entity)
        Catch ex As ApplicationException
            Return ex
        End Try
    End Function

SetValidator finds the proper validator for an entity and sets it through the accessor Entity.Validator.

The problem is: calling Entity.ValidateEntity() dosen't result in the proper method in the validator being fired. I have to call Entity.Validator.ValidateEntity(Entity). What is really irritiating is that ValidateEntityBeforeSave is being called the way it should be!

What am i doing wrong here?

Are you sure that Validator is set? Because ValidateEntity does:


/// <summary>
/// General validation method which isn't used by the LLBLGen Pro framework, but can be used by your own code to validate an entity at any given moment.
/// </summary>
public virtual void ValidateEntity()
{
    if( _validator != null )
    {
        _validator.ValidateEntity(this);
    }
}

another issue is the implementation of IDataErrorInfo. Until now i had been collecting error-messages and displaying by searching for the binding element on the form. I am using janus controls on my form, do i need to add extra code in order for these messages to appear for the controls? Thank you very much in advance for your help

You should add an errorprovider control to your form.

Frans Bouma | Lead developer LLBLGen Pro
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 27-Mar-2007 12:12:27   

Dear Otis, i cleared the directories, rechecked the references, regenerated, and recompiled and the calls to the validation routines went through!

Thank you very much for the support!