OnValidateEntityBeforeSave not firing. :?

Posts   
 
    
Dunebuggy
User
Posts: 8
Joined: 18-Sep-2007
# Posted on: 20-Sep-2007 11:27:35   

Hello,

In my current project i'm having a problem. The OnValidateEntityBeforeSave is not called whilst expecting it should here. I'm currently using .NET2.0 and LLBLGen Pro 2.5

In short I designed a new usercontrol with the fields of a RelatieEntity, bound to a RelatieEntityBindingSource. I then do the following in code to create a new entity.


' create a new relatie panel with a new entity attached to the entitybinding source.
Dim pnl = New RelatiePanel(New RelatieEntity())

Inside the panel there is a save method which will do the follwing to save the entity.


    Public Sub Save()
        Dim relatie As RelatieEntity = CType(RelatieEntityBindingSource.Current, RelatieEntity)
        Try
            relatie.Save()
        Catch ex As Exception
            ' Write an error 
        End Try
    End Sub

When i make the call to relatie.Save i expect the OnValidateEntityBeforeSave to fire but it doesn't.

I implemented a partial class for overriding the handler like so


Namespace MyApp.LLBLGen.EntityClasses
    Partial Public Class RelatieEntity
        Protected Overrides Sub OnValidateEntityBeforeSave()
            MyBase.OnValidateEntityBeforeSave()
        End Sub

        Protected Overrides Function OnValidateFieldValue(ByVal fieldIndex As Integer, ByVal value As Object) As Boolean
            MyBase.OnValidateFieldValue(fieldIndex, value)
        End Sub

    End Class
End Namespace

I placed two breakpoints. One inside OnValidateFieldValue and one in OnValidateEntityBeforeSave. It does break in OnValidateFieldValue but it does not break in the OnValidateEntityBeforeSave.

I also tried using a Validator class but i got the same problem there.

The reason i'm using the OnValidateEntityBeforeSave is to check if a Code field is set. If the field is not set i generate a new unique value for it and set it just before the entity is inserted into the database.

Hope you can help me with this problem ( / bug )

Kind regards,

Daniƫl

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2007 11:43:50   

Before you call the save method, would you please check the values of the following properties. relatie.IsDirty relatie.IsNew If both are false, then the entity won't be saved and the OnValidateEntityBeforeSave won't be called.

Dunebuggy
User
Posts: 8
Joined: 18-Sep-2007
# Posted on: 20-Sep-2007 12:10:54   

In this case relatie.IsNew is true and relatie.IsDirty is false.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2007 12:20:09   

Would you please try to set IsDirty to true?

Dunebuggy
User
Posts: 8
Joined: 18-Sep-2007
# Posted on: 20-Sep-2007 12:30:47   

I figured something out after you made the remark of the **IsDirty **flag.

Up until now i just made a new entity and clicked save immediately. It seems that even though the entity is a new one (Isnew is true) it wont save the (empty) entity to the database. After changing a value and pressing save it still didn't save the entity. However after changing the value and moving to the next field will change the underlying entity, actually setting the IsDirty flag to true. Because i got the OnValidateEntityBeforeSave in this case.

So it seems the underlying save code only checks wether IsDirty is true allowing the save to be performed.

Is there a setting i should use to enable storing "empty" entities ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2007 12:58:12   

Is there a setting i should use to enable storing "empty" entities ?

Nothing than setting the IsDirty to true.

Dunebuggy
User
Posts: 8
Joined: 18-Sep-2007
# Posted on: 20-Sep-2007 13:03:48   

Okey, thank you for the help wink