Sequence of validator calls

Posts   
 
    
KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 12-Jul-2007 13:28:19   

LLBLGen 2.0.7.424 / ASP.net 2 / Adapter

Hi!

I've just realized that Validator classes are called AFTER the data has been inserted in the database. I found this by having a data consistency check in a validator class and in the DB (unique key constraint). The thrown exception comes from the db and not from the validator.. My question now is in what sequence is data saved. Is it like this:

  1. Open transaction
  2. Execute INSERT or UPDATE
  3. Execute ValidateEntityBeforeSave in Validator class --> this may change the data again.
  4. Execute another UPDATE statement that writes the changes done in the Validator (if there are some).
  5. Commit transaction

Is my understanding correct?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jul-2007 15:03:46   

Is my understanding correct?

I'm afraid not.

Entities can be validated in various contexts: OnValidateEntityAfterLoad. This method is called right after the entity has been filled with data and is ready to be used. Use this method to be sure a loaded entity contains the data you expect it to have. If the fetch method specifies a prefetch path, the entity is validated before the prefetch path has been loaded as well. All AfterLoad validation is performed right after the entity's own fetch routine has been completed and the state has been set. For bulk fetches of entities into collections, the entity is validated right before the entity will be added to the collection. OnValidateEntityBeforeSave. This method is called right before the save sequence for the entity will start. OnValidateEntityAfterSave. This method is called when the entity's save action has been completed and a refetch (if applicable) has taken place. If a refetch action takes place (Adapter) the AfterLoad validation is performed before this event. In SelfServicing, refetching of an entity occurs when a property is accessed after a save, so in SelfServicing AfterLoad will take place after AfterSave validation. OnValidateEntityBeforeDelete. This method is called when the entity's delete action is about to be executed.

So the sequesnce would be as follows:

  1. Open transaction
  2. Validate the entity before save, and do any data modification here. (ValidateEntityBeforeSave)
  3. Execute INSERT or UPDATE (once)
  4. Commit transaction
KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 12-Jul-2007 16:08:42   

Thanks for your answer.

Ok in this case I just know that my code doesn't behave as it should.. disappointed Apparently, I'm gonna do some debug sessions... cry

Cheers.