Probably common problem with databinding - EndEdit related?

Posts   
 
    
JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 26-Jan-2007 15:09:58   

I have custom code in the entity which changes the CheckOut value when the DurationOfStay is changed (Same entity).

I have a textbox bound to the CheckOut field but when the information changes, the textbox isn't refreshing until I save.

I can check the data is changed with debug stuff to display the value in memory and, as I mentioned, when I save it, it updates. This, along with some scouring of these forums, would suggest that it is a problem of some kind of EndEdit not being called or something like that. I tried calling OnPropertyChanged("CheckOut") but that didn't do it. How can I trigger EndEdit on the individual field?

The code in my entity class is:

Public Overrides Property durationofstay() As Integer
    Get
        Return MyBase.DurationOfStay
    End Get
    Set(ByVal Value As Integer)
        If Value > 0 Then
            Me.CheckOut = Me.checkin.AddDays(Value)
            MyBase.DurationOfStay = Value
            Me.AmendNightRoomRates()
            'Call OnPropertyChanged("CheckOut")
        Else
            MyBase.DurationOfStay = 0
        End If
    End Set
End Property
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jan-2007 15:52:59   

The EntityField.EndEdit() is available, but it is an empty function with no implementation.

The EndEdit() spoken about before is the one in the EntityClasses (inherited from EntityBase & EntityBase2).

So you can call Me.EndEdit

EndEdit is a public method on the entity. although it doesn't showup in the intellisense, it was ment to be used by databinding code only.

JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 26-Jan-2007 15:57:29   

Thanks Walaa, one problem is I want to be able to back out of this edit. If I do EndEdit it seems to save the changes back to the database sometimes but not always...

Why does EntityField.EndEdit have no implementation?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jan-2007 16:10:34   

Thanks Walaa, one problem is I want to be able to back out of this edit. If I do EndEdit it seems to save the changes back to the database sometimes but not always...

Are you using LLBLGenProDataSource (webApp)? If so you can always use LivePersistence = false, and control the database interactions yourself. Please check the "LivePersistence and events" section in the LLBLGen Pro manual: "USing the generated code - > Adapter/SelfServicing -> Databinding at design time and runtime -> Databinding with ASP.NET 2.0"

JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 26-Jan-2007 16:14:14   

No, sorry. It's a Windows forms based app usinb VB 2005 and LLBLGenPro 2.0

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Jan-2007 16:38:04   

It does have an implementation, but we marked it hidden for intellisense, as in general you shouldn't be calling it directly.

The downside of calling EndEdit() is that if the same entity is also edited in a grid and you would make changes there and press ESC, these changes aren't rolled back. Though if you don't have that situation, it's fine to call EndEdit().

Frans Bouma | Lead developer LLBLGen Pro
JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 26-Jan-2007 16:44:32   

A problem I have if I use Me.EndEdit in this code is that, if I change it a couple of times it saves it to the database - I don't want that to happen until my user hits save changes, my cancel changes button is broken by using Me.EndEdit

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Jan-2007 17:41:24   

JMitchell wrote:

A problem I have if I use Me.EndEdit in this code is that, if I change it a couple of times it saves it to the database - I don't want that to happen until my user hits save changes, my cancel changes button is broken by using Me.EndEdit

An explanation what happens is in this thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8381 (I think it applies to your situation as well).

I don't understand why EndEdit will trigger a save to the database, could you please elaborate on that a bit more? simple_smile .

Cancel changes could be implemented through SaveFields(name) and RollbackFields(name) on the entity, which are meant for this purpose.

Frans Bouma | Lead developer LLBLGen Pro
JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 26-Jan-2007 17:49:33   

I have a few large linked entities and use TopLevelEntityInstance.Save(True) to save and for cancelling changes I just re-load the entity without saving...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Jan-2007 17:52:27   

JMitchell wrote:

I have a few large linked entities and use TopLevelEntityInstance.Save(True) to save and for cancelling changes I just re-load the entity without saving...

Ok, though EndEdit just raises events, why would that trigger save actions, or did you bind a handler to EntityContentsChanged ?

Frans Bouma | Lead developer LLBLGen Pro
JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 26-Jan-2007 18:19:05   

Sorry, it appears the undo changes thing could be to blame rage

I'd never done anything with this bit of the code so I'd not tested it in this way.

Thanks for your help

EDIT

No it isn't.

I opened SQL Server Enterprise Manager, changed information on a different field, changed my check out date a few times and re-queried SQL Server Enterprise Manager and the information on the other field had changed - somehow it's saving the entire entity.

I'm not binding any handlers to EntityContentsChanged as far as I can see.

If I remove the Me.EndEdit call from the custom code, I still see this symptom so it's down to something else I've yet to discover and it's gone fantastically off topic if I want to get into that...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Jan-2007 18:51:44   

Hmm, you could place a breakpoint in the save method of the entity, and then examine the call stack to see where the call originates from.

Frans Bouma | Lead developer LLBLGen Pro