none
What is the best way delete a record on the client side when "IsDone" = true RRS feed

  • Question

  • I have a static filtered scope on the server that will only pull down data when [TableName]IsDone  = false.

    This works great now on the client when IsDone is set to True I want the changes to be pushed up to the server and the record to me removed from the client as it no longer meets the filtered scope.

    This seems like a very common use of any sync pattern. What would be nice is for the framework to have a SyscDirection UpLoadThenDeleate. 

    But for now who would you do this? I have tried to delete the record from the client and do a sync but it looks like stuff in the tracking table needs to be purged as well.

    So what’s the way to do this? I’m using 2.1

    • Edited by INuke Tuesday, December 14, 2010 5:15 PM
    Tuesday, November 23, 2010 4:14 PM

Answers

  • void LocalDataCache1ServerSyncProvider_ChangesSelected(object sender, Microsoft.Synchronization.Data.ChangesSelectedEventArgs e)
     {
      //let's check if we're synching the table we're interested
      if (e.Context.DataSet.Tables.Contains("YourTable"))
      {
      var dataTable = e.Context.DataSet.Tables["YourTable"];
      for (int j = 0; j < dataTable.Rows.Count; j++)
      {
       DataRow row = dataTable.Rows[j];
    
       // we're only interested in deletes
       if (row.RowState == DataRowState.Deleted)
       {
          // let's remove the row so it doesnt get uploaded
    dataTable.Rows.Remove(row); } } } }
    after every sync, you will delete rows where IsDone=true from the client outside of Sync Fx.
    the next time you sync, these deleted rows will of course be picked up by Sync Fx. but since you dont want these rows from being deleted on the server
    you will then remove these rows from dataset that the client gives to the server.
    • Marked as answer by INuke Wednesday, December 15, 2010 12:58 PM
    Wednesday, December 15, 2010 1:13 AM
    Moderator

All replies

  • on your ChangesSelected event on the client side, make sure you filter out deleted rows. check this post:  http://social.microsoft.com/Forums/en-US/syncdevdiscussions/thread/fbc354b7-6b5e-43f7-9560-e1d86477b161

    then after applying changes or  synching, make sure you delete the rows from your client where IsDone=True.

    So you upload first, then delete. the next sync would upload IsDone=True, then delete and the same thing happens on the next sync.

    Tuesday, November 23, 2010 11:34 PM
    Moderator
  • This will deleate the record on the server as well this is not what I want to do I want to keep the record on the server with the IsDone flag set to True and the record removed from the Client. The above work but it removes the record on the server on the next cleint Sync as it 'sees" that as the record was deleted.
    Tuesday, December 14, 2010 5:13 PM
  • you'll have to change it of course to suit your needs. in your case, you will not make a call to Delete but rather remove to take out the row from the dataset so it doesnt get sent to the server.
    Tuesday, December 14, 2010 11:07 PM
    Moderator
  • you'll have to change it of course to suit your needs. in your case, you will not make a call to Delete but rather remove to take out the row from the dataset so it doesnt get sent to the server.

    Not sure what you mean take it out from the dataset. That is what I'm asking I guess how whould I do that? If I have a record on the client side that needs to be sync to the server, example when I change the IsDone to True how do I remove that record for the Sync scope. Let say the ID of the record is 1  so on my client SQLCE database I have that record as it was in scope, IsDone = false. Now I'm done with this record but need to sync the changes up to the server. Works great. No How do I remove the record from the Client side DB without deleting it?
    Tuesday, December 14, 2010 11:25 PM
  • void LocalDataCache1ServerSyncProvider_ChangesSelected(object sender, Microsoft.Synchronization.Data.ChangesSelectedEventArgs e)
     {
      //let's check if we're synching the table we're interested
      if (e.Context.DataSet.Tables.Contains("YourTable"))
      {
      var dataTable = e.Context.DataSet.Tables["YourTable"];
      for (int j = 0; j < dataTable.Rows.Count; j++)
      {
       DataRow row = dataTable.Rows[j];
    
       // we're only interested in deletes
       if (row.RowState == DataRowState.Deleted)
       {
          // let's remove the row so it doesnt get uploaded
    dataTable.Rows.Remove(row); } } } }
    after every sync, you will delete rows where IsDone=true from the client outside of Sync Fx.
    the next time you sync, these deleted rows will of course be picked up by Sync Fx. but since you dont want these rows from being deleted on the server
    you will then remove these rows from dataset that the client gives to the server.
    • Marked as answer by INuke Wednesday, December 15, 2010 12:58 PM
    Wednesday, December 15, 2010 1:13 AM
    Moderator
  • void LocalDataCache1ServerSyncProvider_ChangesSelected(object sender, Microsoft.Synchronization.Data.ChangesSelectedEventArgs e)
    
     {
    
     //let's check if we're synching the table we're interested
    
     if (e.Context.DataSet.Tables.Contains("YourTable"))
    
     {
    
     var dataTable = e.Context.DataSet.Tables["YourTable"];
    
     for (int j = 0; j < dataTable.Rows.Count; j++)
    
     {
    
      DataRow row = dataTable.Rows[j];
    
    
    
      // we're only interested in deletes
    
      if (row.RowState == DataRowState.Deleted)
    
      {
    
       // let's remove the row so it doesnt get uploaded
    dataTable.Rows.Remove(row); } } } }
    after every sync, you will delete rows where IsDone=true from the client outside of Sync Fx.
    the next time you sync, these deleted rows will of course be picked up by Sync Fx. but since you dont want these rows from being deleted on the server
    you will then remove these rows from dataset that the client gives to the server.

    Yes this is what I was looking for Thanks!
    Wednesday, December 15, 2010 1:00 PM