Do Not Update All Columns in Local Storage

Do Not Update All Columns in Local Storage

  

I have an entity on the server, and a table on LocalStorage on mobile that differ by one column. The local storage entity has an extra column. When I sync the server entity down to the local entity, I want the column on the local entity to remain untouched by the sync, and all the other columns only are updated.

I can sync the columns I want using CreateOrUpdateAll, but it always 'blanks out' the extra column on my local storage with the default null value.

I tried instead using a Get action, assigning only the columns I need, and setting the CreateOrUpdateLocal action to be the Get.Record. HOWEVER, when I do the Get action and the ID of the row doesn't exist locally an exception is thrown.

Is there a better way to sync all but one column from server to mobile, or is there a way to stop it throwing an error if the local id doesn't exist and to create that row instead as part of the sync?


Edit:

I should add that when using CreateOrUpdateAll, I get the following mapping:

The ReadDate column I don't want mapping, but cannot see a way to delete it.

Solution

Hi Russell,

It depends a bit on your scenerio. If you want to use CreateOrUpdateAll, I would opt for a seperate Local Entity that holds all values (even if it's just a single column) that has an Id that's of the other Entity's Id (so if you have a LocalCustomer, have a LocalCustomerLocalOnly (or some more sensible name) that has an Id of type LocalCustomer Id). Alternatively, you could like you say retrieve the current from the database. To prevent the Exception you could either wrap the Get in an Action (and handle the Exception gracefully), or use an Aggregate instead (and check whether any data came back).

Solution

Thanks Kilian, in the end I've gone with an aggregate and checking whether the list returned is empty, thank you for helping me think through my logic.

You're most welcome! Happy coding :)