SQL Express Change Tracking Framework – Part 3 : Sync Direction - Death By Patterns

SQL Express Change Tracking Framework – Part 3 : Sync Direction

 

 

Last time we created a basic client server demo showing how to synchronise data between a CE client and a server using Sync Services for ADO.Net and WCF for the communication.  The next step in the process is understanding what sync direction is and how to use it.

What is Sync Direction

Sync direction allows us to specify which tables must be synchronised in what direction.  A table’s sync direction can be specified to be either:

  • Download only
  • Upload only
  • Bidirectional
  • Snapshot

Download only means that changes made to the client table are not synchronised with the server.  The client can still make changes to the table, but those changes aren’t reflected on the server at all.

Upload only is the opposite.  Changes made on the server side are ignored, and only changes made on the client are synched.

Bidirectional means that changes made on either the client or the server are synched.

Snapshot means that when the table is synced it takes a snapshot of the server table and makes the client table the same.  All client data is overwritten.  This is useful in tables where you need the clients tables to match the server’s (e.g. lookup tables) regardless of what’s happening on the client.

How do we use Sync Direction?

Sync Direction is specified on the client sync provider.  In order to specify a direction you simply have to provide a value for the SyncDirection property on the SyncTable class.  If you want the server to have control over the sync direction of a table you have to work a whole lot of extra logic into the DbServerSyncProvider class to check if the changes to/from the client must be applied.

Remember that the wizard created a SyncTable class for each of the tables we specified.  Each of these classes was a strongly typed implementation of the SyncTable class, but we don’t have to extend SyncTable to benefit from the behaviour (more on this when we jump into the SQLExpress client though).

By default the SyncDirection on a table is set to Download Only, so if you need BiDirectional or need to upload changes then we need to change this behaviour.  Right click on the Client Sync Cache file (JoesDeliCache.sync in this case) and select view code.  In the partial class there will be an OnInitialized() method. Add the following code:

partial void OnInitialized()
{
BaseIngredients.SyncDirection = SyncDirection.Bidirectional;
}

Do the same for each table that needs it’s behaviour changed.  Now when you try and sync a download only table after making changes on the client side you’ll see that no changes are applied.

Simple as that!

Next time:
Filtering data based on the client.

Published Wednesday, April 08, 2009 5:44 PM by CalmYourself
Filed under:

Comments

No Comments