locked
LIGHTSWITCH HTML ENTITY SOFT DELETION RRS feed

  • Question

  • Hello all,

    I am working on LightSwitch HTML client application. I have an issue regarding entity soft deletion.

    For your kind information, I have also referred Beth Messi's link:

    http://blogs.msdn.com/b/bethmassi/archive/2011/11/18/using-the-save-and-query-pipeline-to-archive-deleted-records.aspx

    My Scenario:  

    I have an Accounts table which is related to other tables.

    In Accounts edit screen, I have a delete button. On deleting account from edit screen Account should be marked as deleted in database(i.e. soft delete) if it has no reference in any other table, otherwise show client side an error message

    myapp.EditAccount.DeleteAccount_Tap_execute = function (screen) {
    	// Write code here.
            screen.Account.deleteEntity();
    	myapp.applyChanges().then(function success() {
    
                 // Delete successful message.
    
    	}, function error(e) {
    
                // Delete failure message.
    
    	});		
    };

    According to Beth Messi's example: On deletion, the entity will discard changes and mark the entity as soft deleted. 

    So, If data is discarded then I do not get the server side exception " Could not delete. entity is in use." and my code inside function error() could not execute.

    Any different way to accomplish this is also appreciated.  

    Thanks,

    Ravi Patel





    • Edited by Ravii Patel Wednesday, January 28, 2015 2:30 PM
    Wednesday, January 28, 2015 2:26 PM

All replies

  • HI Ravi,

    As Beth’s blog said, it marks records for deletion without actually deleting them from the database. It discards the changes, this reverts the deletion.

    As I know, myapp.applyChanges(), calling apply will save all the changes of the current changeset. If only one changeset exists, it will save them to the database. If the current changeset is a nested scope, it will commit the changes to the parent changeset. I don’t think you can use myapp.applyChanges() method in this scenario.

    Best regards,

    Angie 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 2, 2015 9:50 AM
  • myapp.EditAccount.DeleteAccount_Tap_execute = function (screen) {
        // Write code here.
             screen.Account.deleteEntity();
       return myapp.commitChanges().then(null, function fail(e)  {
            myapp.cancelChanges();
            throw e;
        });

    };

    This will apply the delete

    Monday, February 2, 2015 10:53 PM
  • Hi Angie,

    Thanks for the reply..

    But I am also discarding the changes on server side method

    partial void Accounts_Deleting(Account entity)
    {
    	entity.Details.DiscardChanges();
    	entity.IsDeleted = true;
    }

    The above code is as per Beth's blog. It will discard every time when I try to delete the entity.

    But what I need is on deletion, if the account entity is not used anywhere then set IsDeleted property of that record to "true" else show message "Sorry Account can't be deleted. It is in use".

    Thanks,

    Ravi Patel


    • Edited by Ravii Patel Tuesday, February 3, 2015 5:51 AM
    Tuesday, February 3, 2015 5:50 AM