Sync Offline Table Conflict Example #178
atexinspect
started this conversation in
General
Replies: 2 comments 3 replies
-
I don't right now. However, it should be easy to do as we don't hide the tables any more. Short version:
Something like: using var context = GetDbContext();
foreach (var failedRequestKV in pushResult.FailedRequests)
{
string operationId = failedRequestKV.Key;
DatasyncOperation operation = context.DatasyncOperationsQueue.SingleOrDefault(x => x.Id == operationId);
// operation has the ItemId and EntityType of the entity change that is queued.
// Item is the JSON representation of the client-side value; you can also get the client side value from
// the database.
ServerResponse response = failedRequestKV.Value;
// response is actually a ServerResponse<T> where T is the EntityType as a type.
// response.Content is the JSON representation of the server-side value
// (response as ServerResponse<T>).Value is the server side value.
// You now have both client side and server side in both JSON and concrete values. Do the necessary updates
// and then do the following:
// Delete the operations queue request
context.DatasyncOperationsQueue.Remove(operation);
// Save changes without updating the queue
await context.SaveChangesAsync(true, addToQueue: false);
} Obviously, this is a lot of pseudo-code. I'm happy to consider design changes here. Perhaps, when we create the Offline Options Builder, we do something like: protected override void OnDatasyncInitialization(DatasyncOfflineOptionsBuilder optionsBuilder)
{
options.UseEndpoint(new Uri("https://MYENDPOINT.azurewebsites.net"));
options.Entity<Movie>(cfg => {
cfg.ClientName = "movies";
cfg.Endpoint = new Uri("/api/movies", UriKind.Relative),
cfg.Query.Where(x => x.Rating != MovieRating.R)
cfg.ConflictHandling = ConflictHandling.UseServerEntity;
});
} Basically,
Thoughts on this? |
Beta Was this translation helpful? Give feedback.
3 replies
-
See Issue #298 for the discussion and ultimately implementation of the conflict resolution. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Adrian,
I am updating a legacy application that uses your previous Microsoft.Datasync.Client/Microsoft.Datasync.Client.SQLiteStore V6.1.0
packages. Previously during a sync I could do something similar to the below code and always revert to the servers version on a conflict.
Have you an example of how to do this using the new Community Toolkit version? I am struggling to figure it out.
Thanks
Paul.
https://learn.microsoft.com/en-us/previous-versions/azure/developer/mobile-apps/azure-mobile-apps/howto/client/dotnet
Beta Was this translation helpful? Give feedback.
All reactions