CslaAutoCloneOnUpdate issue?

CslaAutoCloneOnUpdate issue?

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


ixman posted on Wednesday, November 07, 2007

Hi,

I have a strange behavior working with the CslaDataProvider and WPF. I have a LocalDataPortal configuration.

The problem occurred when I’ve added the CslaAutoCloneOnUpdate = True.

The problem is that before CslaDataProvider.Save() method call, the BO IsDirty property is True, this is correct, but after the Save call, the IsDirty is still true and this is wrong because will save the object again(the BO behind the Data property is not synchronized). Going deeper i found that when I set the "AutoUpdate" to true there is no cloning performed :(

The condition for cloning the object is like this (CslaDataProvider.cs):

 .......

if (!Csla.ApplicationContext.AutoCloneOnUpdate)

          {

            // clone the object if possible

            ICloneable clonable = savable as ICloneable;

            if (clonable != null)

              savable = (Csla.Core.ISavable)clonable.Clone();

          }

 

From this code I understand that when CslaAutoCloneOnUpdate = True the condition is FALSE, so no cloning is performed. Is this correct?

I think something is wrong here...

 

Thanks for any comments on this,

George

RockfordLhotka replied on Wednesday, November 07, 2007

No, that should be correct. If AutoCloneOnUpdate is true, then the data portal does the clone. That occurs in the client-side data portal.

CslaDataProvider and EditableRootListBase both do cloning "manually" only if AutoCloneOnUpdate is false - otherwise you'd get duplicate cloning.

ixman replied on Thursday, November 08, 2007

Hi Rocky,

 

Thanks for the answer.

My issue with the AutoCloneOnUpdate is that if I have it set to true, then in the code behind in my xaml page, I have something like this:

 

private void Save_Click(object sender, RoutedEventArgs e)

{

CslaDataProvider documentTypesProvider = (CslaDataProvider)FindResource("DocumentsTypesProvider");

            documentTypesProvider.Save();

}

 

The problem is that after the Save() the IsDirty property of the CslaDataProvider BO ((DocumentTypes)(documentTypesProvider.Data)).IsDirty is still true, which I think is not correct (the clone and the real object that I’m using in the binding are not synchronized correctly?).

If I put in the config AutoCloneOnUpdate = False, I get false for IsDirty after the Save().

Is this a correct behaviour?

 

 

Thanks,

George Barbu

RockfordLhotka replied on Monday, November 12, 2007

I ran into something similar, perhaps this is the same issue.

 

The WPF data binding infrastructure doesn’t treat Equals() like it should (in my view). So if a data provider (or any datacontext) is set to an object that is equal to (using Equals()) the previous object, then the new object is ignored. It is an “optimization”, but it means you cannot use logical equality between objects.

 

If you have C1 and C1’ – two instances of exactly the same object they are equal, even if they are different objects right?

 

But what does equality mean? Does it mean all fields of the object, and all child objects, are identical? Sure.

 

Does it mean that C1.Id = C2.Id? Maybe. You might say yes, that is equality, and it is a valid form of logical equality to make that statement. CSLA does this.

 

Unfortunately WPF, in their wisdom, says that NEITHER of those two are correct. If Equals() returns true they ignore the new object. And this sucks, because in either of those two cases you might have very valid reasons for wanting to use the new object instance.

 

WPF should have used ReferenceEquals() to do their optimization, but they messed up. In my view anyway.

 

So it is possible that you are getting back (within CslaDataProvider) a new object instance, which is being ignored by data binding in WPF.

 

However, that really shouldn’t happen, because I put code in CslaDataProvider to overcome this issue by setting the datacontext to null/Nothing and then back to the new object.

 

However, I ran into issues there, because of YAO (yet another optimization) where it appears that the datacontext isn’t restored immediately from the provider, so the setting-the-value-to-null step is ignored. Ugh. Version 1.0 technologies can be a pain…

 

I did solve my particular case, but I don’t know that it is a real solution – it involved some quirky UI code.

 

This is a long-winded way of saying that I realize there are some issues here – but I don’t know of a good solution as yet. If you find any workarounds or solutions, please share them!

 

Rocky

 

 

From: ixman [mailto:cslanet@lhotka.net]
Sent: Thursday, November 08, 2007 8:04 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CslaAutoCloneOnUpdate issue?

 

Hi Rocky,

 

Thanks for the answer.

My issue with the AutoCloneOnUpdate is that if I have it set to true, then in the code behind in my xaml page, I have something like this:

 

private void Save_Click(object sender, RoutedEventArgs e)

{

CslaDataProvider documentTypesProvider = (CslaDataProvider)FindResource("DocumentsTypesProvider");

            documentTypesProvider.Save();

}

 

The problem is that after the Save() the IsDirty property of the CslaDataProvider BO ((DocumentTypes)(documentTypesProvider.Data)).IsDirty is still true, which I think is not correct (the clone and the real object that I’m using in the binding are not synchronized correctly?).

If I put in the config AutoCloneOnUpdate = False, I get false for IsDirty after the Save().

Is this a correct behaviour?

 

 

Thanks,

George Barbu



Copyright (c) Marimer LLC