When using the CslaActionExtender there exists the following problem.
Take the following actions:
Show a form to edit for example a customer object.
Stop SQL Server to simulate an error.
Click on the OK button of the Customer form.
An error will be raised to say that no connection to SQL Server can be done.
Until now the behavior is as expected.
Start SQL Server again.
Try again to click on the OK button.
We get the following error:
System.InvalidCastException: The underlying data source does not cast to a CSLA BusinessBase object
This behavior is not as expected because the save should work now.
The problem is that the data source is empty. In case of an error you should call _bindingSourceTree.Bind(savableObject) no matter what PostSaveAction you have. Even in the case AndClose you should rebind the datasource so the user can try again to save the object.
Below follows the code of CslaActionExtender with an added line of code which solves the problem in my opinion.
Lhotka : can you have a look at this suggestion?
protectedvoid OnClick(object sender, System.EventArgs e).....
try{
savableObject = savableObject.Save()
as Csla.Core.ISavable;...
}
catch (Exception ex)
{
_bindingSourceTree.Bind(savableObject);
//by adding this line of code it solves the problemOnErrorEncountered(newErrorEncounteredEventArgs(props.CommandName, newObjectSaveException(ex)));
raiseClicked = false;
}