locked
How to set mergedEntity object during a conflict. SyncConflictResolution RRS feed

  • Question

  • Hi All,

    I am not able to implement Sync Framework on my application. I have some queries, searched through the web but din't find any solution. I am following the Sample WP7 Code which is provided in C:\Program Files\microsoft SDKs\MS Sync Framework\v4.0\Sample\WP7Application. In that there is List Webservice, in that conflict handling is done.

    I have a scenario when my WP7is changing the some columns of the entity. And simultaneous changes are done on the SQL Server on the same instance(on the same row) on some different columns. Conflict has occured, if in the service, I write 'SyncConflictResolution.ClientWins', it works fine. But I want to merge the changes in the instance, whenever I write 'SyncConflictResolution.Merge', I have to set the mergedEntity object as it is not allowing null value. I dont know how to do it. Can anyone tell me with example?

            [SyncConflictInterceptor("DefaultScope")]
            public SyncConflictResolution ConflictHandler(SyncConflictContext context, out IOfflineEntity mergedEntity)
            {
                // Add a dummy header to the response indicating that the interceptor method was invoked.
                context.ResponseHeaders.Add("ConflictInterceptorFired", "true");
                // The mergedEntity is used as the winner of the conflict
                // when this method returns SyncConflictResolution.Merge as the resolution.
                // For other resolutions such as SyncConflictResolution.ClientWins and SyncConflictResolution.ServerWins
                // the mergedEntity should be set to null.
                mergedEntity = null;
               
                return SyncConflictResolution.Merge;
            }

     

    Can anyone tell me how to go ahead with this. Thanks in advance

    Regards

    Kushal

    Monday, January 9, 2012 12:45 PM

All replies

  • Hi Kushal,

    Check this doc out:

    http://msdn.microsoft.com/en-us/library/gg299068(v=sql.110).aspx

    Specifically:

    The SyncConflictContext contains information related to the conflict. In case of a custom merge resolution users can return a new mergedEntity in the output parameter for the runtime to use. The mergeEntity represents the version that will be applied on the backend data store. When a merged entity is sent, a return value of SyncConflictResolution.Merge must be sent. It is invalid to send a non-null value for merge when returning SyncConflictResolution.Merge. However, mergeEntity should be set to null when returning SyncConflictResolution.ClientWins and SyncConflictResolution.ServerWins. For SyncConflictResolution.ClientWins, the version that will be applied to the backend data store will be the entity in SyncConflictContext.ClientChange, and for SyncconflictResolution.ServerWIns, the version that will be applied to the backend data store will be SyncConflictContext.ServerChange. For both these cases, the value of mergeEntity will be ignored.

    -Jesse

    Monday, January 9, 2012 6:23 PM
  • Sync Framework track changes at the row level and not at the column level. so you have to have a way to determine which columns was changed on both sides to combine/merge the changes.

    when you have figured out how to track the changes, you have to manually assign final values for each column in the merge entity object by reading the entity values in SyncConflictContext.ClientChange and SyncConflictContext.ServerChange

    Tuesday, January 10, 2012 2:40 AM