Silverlight CslaDataProvider - Setting ObjectInstance doesn't clear the Error property.. I think it should?

Silverlight CslaDataProvider - Setting ObjectInstance doesn't clear the Error property.. I think it should?

Old forum URL:

Jaans posted on Monday, July 13, 2009

My scenario requires me to manually fetch and subsequently populate the CslaDataProvider control with the Csla Business Object.

That all works fine as I basically set the CslaDataProvider's ObjectInstance property to the new business object I fetched.

The issue I get is due to an error from a save affecting a subsequently different business object instance.

It can be better understood by considering the following sequence of events:
1) Manually Fetch Data
2) Set CslaDataProvider.ObjectInstance = fetchedData (and the DataChanged event fires as expected).
3) Make object dirty (through edits)
4) Call CslaDataProvider.Save() to save data
5) Save results in an error which populates the CslaDataProvider.Error property accordingly.
6) The DataChanged event fires and the check for Error allows me to catch and handle the error (display message to user)
7) I wish to fetch an other object and set the ObjectInstance to the newly fetched object (as in 1 and 2 above).
8) The DataChanged event fires again, but the Error from the failed save in 5 is still present and this is the problem. I handle an exception for an instance that's no longer referenced by the CslaDataProvider.

My thinking is that setting the ObjectInstance should implicitly clear the error property of the CslaProvider as the error would otherwise have been for a different instance.

The Refresh method (which you would use if you are not implementing the "manual" fetch) does clear the error property before fetching.

Post Edit:
An alternative could be to provide a method to clear the error which I can call before setting the object instance.

Do you agree?

Many thanks

RockfordLhotka replied on Monday, July 13, 2009

This does sound like a bug - I'd also expect Error to clear when ObjectInstance is set.

I'll add it to the bug list.

Jaans replied on Sunday, August 02, 2009

Thanks Rocky!! I can confirm that 3.7.0 fixes the issue. Regards, Jaans

RockfordLhotka replied on Sunday, August 02, 2009



jbd replied on Monday, August 03, 2009

We seem to have hit a problem using the Silverlight CslaDataProvider in 3.7 and we are not sure if it is a bug or something we are doing wrong. It appears When using the Provider to do a Fetch, it seems that errors are not being propogated.


We set up the DataProvider in the xaml like so:


<csla:CslaDataProvider x:Key="DataProvider"


                               ObjectType="IMS.IManager.BoardingPremises, IMS"





And in the code behind we are doing the following:





        this.Provider.FactoryMethod = "GetItem";

        this.Provider.Saved += new EventHandler<Csla.Core.SavedEventArgs>(Provider_Saved);




Running in debug and following it from client to server, and back again there seems to be a problem(?) in the SetObjectInstance method. When the QueryCompleted method is called e.Error shows the error which in our case is a database error, up until the point SetObjectInstance is called. 


490    private void QueryCompleted(object sender, EventArgs e)

491    {

492      IDataPortalResult eventArgs = e as IDataPortalResult;

493      SetError(eventArgs.Error);

494      SetObjectInstance(eventArgs.Object);


Following the code through the error is being pushed into the internal variable _error by SetError at line 345.


343       private void SetError(Exception value)

344    {

345      _error = value;

346      IsBusy = false;

347      OnPropertyChanged(new PropertyChangedEventArgs("Error"));

348    }


SetObjectInstance then sets _error to null at line 164.


153    private void SetObjectInstance(object value)

154    {

155      //hook up event handlers for notificaiton propagation

156      if (_dataObject != null && _dataObject is INotifyPropertyChanged)

157        ((INotifyPropertyChanged)_dataObject).PropertyChanged -= new PropertyChangedEventHandler(dataObject_PropertyChanged);

158      if (_dataObject != null && _dataObject is INotifyChildChanged)

159        ((INotifyChildChanged)_dataObject).ChildChanged -= new EventHandler<ChildChangedEventArgs>(dataObject_ChildChanged);

160      if (_dataObject != null && _dataObject is INotifyBusy)

161        ((INotifyBusy)_dataObject).BusyChanged -= new BusyChangedEventHandler(CslaDataProvider_BusyChanged);


163      _dataObject = value;

164      _error = null;


So when we do the following in the DataChanged handler the error is not available and we get some unexpected behaviour. 


private void CslaDataProvider_DataChanged(object sender, EventArgs e)


   if (this.Provider.Data != null)


     // Do Some stuff



   if (this.Provider.Error != null)





RockfordLhotka replied on Monday, August 03, 2009

Definitely seems like a bug, I’ve added it to the list.


Thank you so much for the great technical information on the issue!!



RockfordLhotka replied on Monday, August 03, 2009

This has been fixed in 3.7.1 and 3.8.0

jbd replied on Tuesday, August 04, 2009

Thanks for the quick response

Copyright (c) Marimer LLC