There are no update or delete methods. There's the standard Save(), except that it is BeginSave(), which automatically invokes the data portal to transfer the object graph to the server where the normal DataPortal_XYZ methods are invoked.
BeginSave() takes a paramter that is the callback method, so when the save operation is complete it can call your code to tell you the results. If you are using CslaDataProvider you don't need to do anything - it is just automatic - but if you are using code-behind or a ViewModel then you need to write the callback method. If you are using C# this is a simple lambda, and in VB it is a bit harder but not bad.
Delete works the same as on the .NET side.
There’s deferred deletion, where you call Delete() on the
object so IsDeleted becomes true, then you call BeginSave() so the data portal
invokes DataPortal_DeleteSelf() on the server. Or in the case of a child
object, the child delete method.
And there’s immediate deletion, where you create a static DeleteObject()
“factory method” that calls DataPortal.BeginDelete(), passing in a
criteria object. That works much like DataPortal.BeginCreate() or .BeginFetch().
Rocky
I know this is an old thread but I have a related question. I am using CSLA 4 and Silverlight.
I am usng deferred delete and then calling save. The default behavior of SimpleDataPortal.Update() is to call MarkNew() on the object after returning from the DataPortal_DeleteSelf call.
In ViewModelBase<T>.BeginSave(), the Saved handler sets Model to e.NewObject.
I can see that I really do have the object I just deleted (all properties are still present) and that the record is marked as new.
My question: is there any way for me to know that this object was just deleted?
I have my own base class that derives from ViewModel<T> and I override OnModelChanged() so I know when Model is updated. This would be a convenient place for me to set Model to null in the case of a just deleted object. (In my Silverlight UI, after deleting a record, I will blank out that data entry form when the Model is null).
var dp = new DataPortal<Company>();
DeleteCriteria dc = new DeleteCriteria();
dc.Id = id;
dc.DeleteType = DeleteTypeEnum.DeletePermanent;
dp.DeleteCompleted += callback;
dp.BeginDelete(dp);
}
dc.Id = id;
dc.DeleteType =
DeleteTypeEnum.Inactivate;dp.DeleteCompleted += callback;
dp.BeginDelete(dp);
}
This will call my Company.Server.cs class
This class looks like this
[Csla.Server.
ObjectFactory("EnterpriseObjects.Companies.DataAccess.Company, Company")]dc.Id = id;
dc.DeleteType =
DeleteTypeEnum.DeletePermanent;}
dc.Id = id;
dc.DeleteType =
DeleteTypeEnum.Inactivate;}
}}
Will this work?
Or am I going about this wrong?
Nothing forces your server-side delete methods to actually
delete any data. Remember that you have to implement the DataPortal_Delete() or
DataPortal_DeleteSelf() methods, and you can absolutely update an ‘inactive’
flag instead of deleting any rows of data.
The thing to remember is that the Silverlight client just
invokes the normal .NET server methods. So your data access should be exactly
the same as it is for your Windows applications – only the client parts
of the business objects are slightly different due to the async data portal in
SL.
Rocky
Copyright (c) Marimer LLC