What must do base.ValidateEntity(involvedEntity) funtion ?

Posts   
 
    
Gayane
User
Posts: 10
Joined: 14-Apr-2008
# Posted on: 25-Sep-2008 08:37:54   

I override ValidateEntity function and try to call base.ValidateEntity(involvedEntity) function. As I understand it must do some checking. For example if some field comtains null but it can be null. In that case it must throw an exception. Am I right ? But I tried to save empty row and that function didn't throw any exception, but after that i got exception which i can not handle.

Here is my code

public class TruckValidatorClass:ValidatorBase
{
    public TruckValidatorClass()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    
    public override void ValidateEntity(IEntityCore involvedEntity)
    {
        try
        {
            base.ValidateEntity(involvedEntity);
        }
        catch (ORMEntityValidationException ex)
        {
            involvedEntity.SetEntityError(ex.Message);          
        }
    }

}
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 25-Sep-2008 12:07:45   

base.ValidateEntity(involvedEntity)

It just calls the ValidateEntity implemented in a Validator class, if you supplied a Validator. Please check Generated code - Validation per field or per entity Also in that link, check the Build-In Validation.

but after that i got exception which i can not handle.

Please post the exception and the stack trace.

Gayane
User
Posts: 10
Joined: 14-Apr-2008
# Posted on: 25-Sep-2008 13:17:53   

I am trying to save empty row and after exiting validator function somewhere it checks and finds that one of fields null is not alowed. I want to handle that or to check before that and cancel the save. But in validatior function which i tried to implement that filed is not null it is 0.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 25-Sep-2008 13:51:12   

Maybe that's the default value of the field's type. Check the myEntity.Fields["myField"].IsChanged flag, if it's false then the field was not set and hence won't be inserted in the database.

If all fields have the IsChanged = false, then that's definitly an empty row.

Also Id recommend you override ValidateEntityBeforeSave, ad do your checks there.

Gayane
User
Posts: 10
Joined: 14-Apr-2008
# Posted on: 25-Sep-2008 14:05:08   

Thanks.