How to use IEntityValidator with entitycollection generation

Posts   
 
    
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 09-Mar-2005 22:55:35   

Hi,

In adapter scenario I want to use the IEntityValidator class, so I created my own validator, that implements this interface.

The UI get the collection of myObj:

dim MyObjValidator as IEntityValidator=New MyObjValidator dim MyObjCol as New EntityCollection(new MyObjEntityFactory, MyObjValidator)

This code doesn't work, because the constructor of the EntityCollection requires IValidator as parameter, not IEntityValidator.

In this scenario, how to create collection with custom entity validator?

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Mar-2005 12:04:43   

The entity collections in selfservicing need the reference to add it to newly created entities. In adapter you should use the entity factory classes to insert an IEntityValidator object. Create a derived class of an entity factory and insert the entity validator instance there.

Not having the IEntityValidator object in the entity collection constructor though having the IValidator instance in the constructor is a design flaw. IValidator shouldn't have been there.

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 10-Mar-2005 16:16:15   

Thanks Frans,

I tried to do this:

In a Derived Entity factory class:

Public Class MyDerivedEntityFactory

Public Sub New(ByVal validator as IEntityValidator) MyBase.New() Create().EntityValidatorToUse=validator End sub . .

But it never call validator.Validate confused

I probably missing something, would You like to explain me, how to inoculate the IEntityValidator into the EntityFactory?

Thanks in advance

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Mar-2005 16:34:25   

Validate is called by default when the entity is saved.

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 10-Mar-2005 17:45:58   

Frans,

Unfortunately the validator doesn't invoked when the entity saved.

I save the entity via adapter.SaveEntityCollection(MyCollection) method.

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Mar-2005 17:57:10   

Gabor wrote:

Frans,

Unfortunately the validator doesn't invoked when the entity saved.

I save the entity via adapter.SaveEntityCollection(MyCollection) method.

Thanks

Gabor

Hmm, and the validator IS set?

if you change your code to:


Public Class MyDerivedEntityFactory

Public Sub New(ByVal validator as IEntityValidator)
MyBase.New()
End sub

Public Overrides Overloads Function Create() As IEntity2
Dim toReturn = MyBase.Create()
toReturn.EntityValidatorToUse=validator
return toReturn
End Function

Does it work then?

Also, override all create methods, not just 'Create', but also Create(fields).

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 10-Mar-2005 22:32:19   

Thanks Frans,

With some litle modification it works smile

(Has to declare the modulwide MyValidator, to see from within Create methods)

Dim MyValidator as IENtityValidator

Public Sub New(validator as IEntityValidator) MyBase.New() MyValidator=validator End Sub . . .

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Mar-2005 23:30:48   

Glad it's working! simple_smile

Frans Bouma | Lead developer LLBLGen Pro