Doing Entity Validation

Posts   
 
    
jmcervera
User
Posts: 27
Joined: 03-Jun-2004
# Posted on: 16-Mar-2006 10:59:40   

Hello,

I want to do entity validation using the selfservicing model (version 1.0.2005.1 Final) I am using the two class scenario.

Where is the best place to assing the entityValidator class to the entity class. I see too many ways of doing it.

In the *Entity classes - Constructors in *Entity (not included in custom entity code regions) - User code region CustomEntityCode in *Entity

In the *EntityBase classes - User code region InitClassEmpty in *EntityBase - User code region InitClassFetch in *EntityBase - User code region CustomEntityCode in *EntityBase

And please, some questions that there are not very clear to me.

Is the whole *Entity.cs/vb file going to be preserved in generations? In thas case, why we need user code regions in these classes? What is the Included Code Region for?

Thank you very much.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 16-Mar-2006 15:16:29   

Refering to the LLBLGen Pro documentation "Using the generated code -> Validation per field or per entity" -> "Validation per entity: implementing IEntityValidator"

You should create a class of your own that Implements IEntityValidator as shown on the documentation example, then youe set your entity's EntityValidatorToUse property to an instance of this class as shown in the documentation example.

<EDIT>

Is the whole *Entity.cs/vb file going to be preserved in generations?

Yes

In thas case, why we need user code regions in these classes? What is the Included Code Region for?

Please check the following thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2288

jmcervera
User
Posts: 27
Joined: 03-Jun-2004
# Posted on: 16-Mar-2006 16:03:58   

Thanks Walaa

Walaa wrote:

You should create a class of your own that Implements IEntityValidator as shown on the documentation example, then youe set your entity's EntityValidatorToUse property to an instance of this class as shown in the documentation example.

Yes, I understand this but I want to set instance of the IEntityValidator implementation automatically for every instance of the class, even for entities in a collection loaded by the lazy load behaviour in an object with a related collection of other objects.

In the documentation section "Setting IEntityValidator instances at runtime", talks about the initializing routines in an entity, can you be some more specific with this.

In which user code region is better to set the EntityValidatorToUse property?

In the Entity class or in the EntityBase class ? Or it doesn´t matter?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 17-Mar-2006 07:55:18   

In which user code region is better to set the EntityValidatorToUse property?

In the Entity class or in the EntityBase class ?

I think the best place would be the InitClassEmpty user code region found in the EntityBase.cs/vb of a 2 class scenario.

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 17-Mar-2006 19:52:54   

My .02$ is to ditch EntityValidator altogether and place all logic in the bussiness layer.

Now your using SelfService which, if passed up to you presentation layer, can circumvent the bl.

So, if your writing an app that is even a little complex, then maybe you should switch to adapter. simple_smile