CSLA for SilverLight

CSLA for SilverLight

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


SouthSpawn posted on Friday, July 17, 2009

Quick question.

In SilverLight .net

I am looking at the demo projects for the SilverLight videos that I purchased.

I am confused on the Business.Clent class.

It only has  a "Get" and a "New" method for the SilverLight Client methods.

What is the proper syntax to add the "Update" and "Delete" methods in C#

I am not sure what I pass in for parms in the BeginUpdate method.

Any help would be great.

Thanks,
Mark

RockfordLhotka replied on Saturday, July 18, 2009

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.

SouthSpawn replied on Saturday, July 18, 2009

Wow Rocky, it's pretty late, you still up :) :)

Anyhow,

Ok, so how do I mark an object for deletion.
I can understand the update part, simply because the framework will know to mark the item as old.
So therefore, it knows to perform an update when the save method is called.

But how do I mark an object for deletion?

Sorry for being a pain here, but I am still a little confused.
 
Thanks,
Mark

RockfordLhotka replied on Saturday, July 18, 2009

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

 

artsd replied on Wednesday, January 05, 2011

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).

SouthSpawn replied on Saturday, July 18, 2009

Rocky,

In our business cases, there might times where a "Delete" will not delete actual data from the database, but only Inactivate the record.

There are other times where the actual record may be removed.
 
So here is what I am trying to do on my SilverLight Client.

public
static void DeleteCompany(int id, EventHandler<DataPortalResult<Company> callback)
{

      var dp = new DataPortal<Company>();

      DeleteCriteria dc = new DeleteCriteria();

      dc.Id = id;

      dc.DeleteType = DeleteTypeEnum.DeletePermanent;

      dp.DeleteCompleted += callback;

      dp.BeginDelete(dp);
}

public static void InactivateCompany(int id, EventHandler<DataPortalResult<Company> callback)
{

      var dp = new DataPortal<Company>();

      DeleteCriteria dc = new DeleteCriteria();

      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")]
public partial class Company
{

      public static void DeleteCompany(int id)
      {

            DeleteCriteria dc = new DeleteCriteria();

            dc.Id = id;

            dc.DeleteType = DeleteTypeEnum.DeletePermanent;

            DataPortal.Delete(dc);

      }

      public static void InactivateCompany(int id)
      {
            DeleteCriteria dc = new DeleteCriteria();

            dc.Id = id;

            dc.DeleteType = DeleteTypeEnum.Inactivate;

            DataPortal.Delete(dc);

      }

}


I have a data access class that looks like this.
 

public void Delete(EnterpriseObjects.HelperClasses.DeleteCriteria criteria)
{

// delete data here

}

Will this work?

Or am I going about this wrong?

RockfordLhotka replied on Sunday, July 19, 2009

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