entity validators in separate project

Posts   
 
    
morten71
User
Posts: 80
Joined: 13-Jan-2009
# Posted on: 07-Mar-2014 21:40:19   

I'm following your vs project "Validation Example - Selfservicing" to setup my own validation project (using dependency injection).

Your "ValidateEntityBeforeSave" function in the file OrderValidator.cs in the project "SD.LLBLGen.Pro.Examples.Validators" does not call base.ValidateEntityBeforeSave(involvedEntity); at the end of the function.

Why?

Shouldn't all override validators call the function in the base class?

This is done in the other example (CustomerValidator.cs)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Mar-2014 08:39:58   

Maybe it should call the base method. The base class however didn't implement that as the ValidatorBase is intended to facilitate things, but calling base.ValidateEntityBeforeSave does nothing actually.

David Elizondo | LLBLGen Support Team
morten71
User
Posts: 80
Joined: 13-Jan-2009
# Posted on: 10-Mar-2014 21:02:24   

daelmo wrote:

Maybe it should call the base method. The base class however didn't implement that as the ValidatorBase is intended to facilitate things, but calling base.ValidateEntityBeforeSave does nothing actually.

Hi David. Thx for your reply.

How does the validator classes function when doing save, delete and update multi operations?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Mar-2014 06:41:15   

morten71 wrote:

How does the validator classes function when doing save, delete and update multi operations?

This is explained in detail in the docs. Basically, if you do something like:

adapter.SaveEntityCollection(myCollection);

then each entity inside the entity passes through yourValidator.ValidateEntityBeforeSave and yourValidator.ValidateEntityAfterSave. Similar with adapter.DeleteEntityCollection(myCollection) and yourValidator.ValidateEntityBeforeDelete.

Now, if you do something like:

adapter.ValidateEntityBeforeDelete(newValues, filter);

... it's different, as you are not working with entities, but with a set of new values and a filter. In that case you should write your validation in your own business logic. You should establish what you want to validate and how. In most cases you could do that just using the filter.

David Elizondo | LLBLGen Support Team