Updating EditableRoot contained in a Unit of Work

Updating EditableRoot contained in a Unit of Work

Old forum URL: forums.lhotka.net/forums/t/9742.aspx

jpmir posted on Wednesday, November 10, 2010


I'm trying to use Unit Of Work (ReadOnlyBase) to retrieve in one trip an EditableRootObject and a bunch of NVL, ReadOnlyLists, etc.

Each one of those objects are declared as properties with a private setter... like this:

        Private Shared ReadOnly _AfiliacionProperty As PropertyInfo(Of Afiliacion) = RegisterProperty(Of Afiliacion)(Function(p As AfiliacionUnitOfWork) p.AfiliacionMember, Csla.RelationshipTypes.Child)

Public Property AfiliacionMember() As Afiliacion Implements IUnitOfWork(Of Afiliacion, AfiliacionSecurityObject).Model
                Return GetProperty(_AfiliacionProperty)
            End Get
            Private Set(ByVal value As Afiliacion)
                LoadProperty(_AfiliacionProperty, value)
            End Set
        End Property

        Private Shared _NacionalidadesProperty As PropertyInfo(Of NacionalidadNameValueList) = RegisterProperty(Of NacionalidadNameValueList)(Function(p As AfiliacionUnitOfWork) p.NacionalidadesMember, Csla.RelationshipTypes.Child)

        Public Property NacionalidadesMember As NacionalidadNameValueList
                Return GetProperty(_NacionalidadesProperty)
            End Get
            Private Set(ByVal value As NacionalidadNameValueList)
                LoadProperty(_NacionalidadesProperty, value)
            End Set
        End Property

... And so on.
So far so good, 
As I'm binding some UI elements to AfiliacionMember which is an EditableRootObject, for example: IsSavable, IsDirty, IsBusy, etc... and to the business object properties as well: AfiliacionId, AfiliacionDate, etc. I noticed that the EditableRootObject retrieved with the UOW is never Savable according to the property IsSavable...
If I try to bypass this validation like this
      'If mobjModel.IsSavable Then
      'End If
then an exception is thrown indicating that the object is not ready to be saved.
Now, If I try to ApplyEdit before BeginSave then nothing happens and dataportal_Update never gets called.
The strange part of it is that this works fine when I retrieve the object out of an UOW.
Any Ideas?

RockfordLhotka replied on Wednesday, November 10, 2010

The exception should also tell you why it can't be saved. One of

  1. It is a child
  2. It is still being edited
  3. It is invalid
  4. It is busy

Hard to help you without knowing which of these is the issue.

jpmir replied on Thursday, November 11, 2010

Hi Rocky!,

I guess you missed the "factor number five"!... Badly designed UI custom controls that never raise OnPropertyChanged Events for the Value property...

I'm really sorry for wasting your time like this... It's 1:48am here and I just find this bug.Embarrassed

For anyone interested in this situation, the answer is 

5.- The user( or in my case, the user interface control)  is not reporting changes to Datasource before calling BeginSave so
      nothing has changed and CSLA avoids the trip to the server to save an unchanged object.

This answer why IsSavable was False all the time.

Thank you very much for your time.



Copyright (c) Marimer LLC