Validating a SaveMulti on a Collection

Posts   
 
    
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 30-Nov-2006 16:36:07   

I'm using SelfService. I want to show a Collection in a Janus grid, and validate each Entity when calling SaveMulti.

Here's my form:

Imports WORKBLLv1.CollectionClasses
Public Class Form1

    Dim clnAbils As New Abil001Collection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        clnAbils.GetMulti(Nothing)
        GridEX1.DataSource = clnAbils
        GridEX1.RetrieveStructure()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            clnAbils.SaveMulti()
        Catch
            MsgBox(Err.Description)
        End Try
    End Sub
End Class

In the Abil001Validator class, I've added a ValidateEntityBeforeSave, but this doesn't get called.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Nov-2006 17:03:59   

llblgen 1.0.2005.1 or v2.0? And what's the buildnr of the runtime lib? See: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7720

Frans Bouma | Lead developer LLBLGen Pro
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 30-Nov-2006 17:23:31   

Sorry.

I'm on 2.0.0.0 Demo and SQL Server 2000.

It works if I add these to Abil001Entity class:

Imports WORKBLLv1.ValidatorClasses

...

 ' __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
        Protected Overrides Function CreateValidator() As IValidator
            Return New Abil001Validator()
        End Function
        ' __LLBLGENPRO_USER_CODE_REGION_END 

and do a For Each loop through the Entity Collection.

It fails on unhandled exception if I use SaveMulti.

My main problem here is what is the easiest way to set up a Validator for all Entities easily.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 01-Dec-2006 02:28:57   

Try placing the validation in an override of OnValidateEntityBeforeSave in a partial class for the Abil001Entity class. This is a similar setup using C# and an entity NameEntity.


        public partial class NameEntity : EntityBase, ISerializable
    {
        protected override void OnValidateEntityBeforeSave()
        {
                        Validate
        }
    }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 01-Dec-2006 10:34:49   

As you use the demo, you don't have the SDK, though it's not that hard to generate a small code snippet into the init method to set the proper validator for each class.

However, in practise it turned out that not all entities need a validator, so it's better to simply define a small partial class like bclubb showed you where you add the validation OR set the validator as you've done in the region code by overriding CreateValidator.

Frans Bouma | Lead developer LLBLGen Pro
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 01-Dec-2006 11:20:38   

Thanks.

We've just bought licences so I can edit the template to include generic validation.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 01-Dec-2006 12:25:15   

smile OK. Just post a follow up message to this thread if you need help with the template.

Frans Bouma | Lead developer LLBLGen Pro
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 07-Dec-2006 10:30:52   

bclubb wrote:

Try placing the validation in an override of OnValidateEntityBeforeSave in a partial class for the Abil001Entity class.

The documentation does refer to OnValidateEntityBeforeSave etc, but the method is called ValidateEntityBeforeSave. Am I missing something?

I'm OK with the TemplateStudio so far, except I don't know where to put the exe file so that the Help works.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 07-Dec-2006 10:48:34   

Steve wrote:

bclubb wrote:

Try placing the validation in an override of OnValidateEntityBeforeSave in a partial class for the Abil001Entity class.

The documentation does refer to OnValidateEntityBeforeSave etc, but the method is called ValidateEntityBeforeSave. Am I missing something?

The method in the entity is called OnValidateEntityBeforeSave. It will call the method ValidateEntityBeforeSave of the Validator object set to the entity IF present. So you have two choices: - override OnValidateEntityBeforeSave in a partial class and place the code there. You then don't have to create a validator object and set the entity's Validator property to that object (or override CreateValidator() in the entity class) - create a validator class, derived from ValidatorBase (see manual: 'Using the generated code - Validation per field or per entity' for details and example) and do the validation in there.

I'm OK with the TemplateStudio so far, except I don't know where to put the exe file so that the Help works.

Just unpack the zip in the LLBLGen Pro installation folder. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 07-Dec-2006 11:34:11   

Ah! I see where I'm being dumb.

I was looking for OnValidateEntityBeforeSave in the generated entity class, but it's in the base entity class SD.LLBLGen.Pro.ORMSupportClasses.EntityBase

nefise
User
Posts: 22
Joined: 01-Dec-2006
# Posted on: 07-Dec-2006 13:38:05   

I am trying to update an entityCollection, I bind the Entity collection to the form items with Currency Manager. After the call

adapter.SaveEntityCollection(Apps, true, true)

The Update process fails without any error messages.