Sync Framework: can I only sync a subset of my tables?

A common piece of code to sync data with a sync card is:

LocalDBSyncAgent syncAgent = new LocalDBSyncAgent();
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();

      

Does anyone provide an option to sync a subset of my tables. Don't count the data within each table, but decide which tables will be synchronized.

Thanks Ariel

+1


source to share


2 answers


Yes, you absolutely can.

Create a SyncTable for each table you want to sync and add it to Configuration.SyncTables in SyncAgent.

I found this article by Bill Ryan very instructive. It talks about how to filter the data in each table, but there are things in there that do what you are looking for.



Sample from Bill Ryan:

public class SampleSyncAgent : Microsoft.Synchronization.SyncAgent
 {

     public SampleSyncAgent()
     {

         SqlCeClientSyncProvider clientSyncProvider = new SqlCeClientSyncProvider(Properties.Settings.Default.ClientConnString, true);
         this.LocalProvider = clientSyncProvider;
              clientSyncProvider.ChangesApplied += new EventHandler<ChangesAppliedEventArgs>(clientSyncProvider_ChangesApplied);    

         this.RemoteProvider = new SampleServerSyncProvider();    

         SyncTable customerSyncTable = new SyncTable("Customer");
         customerSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
         customerSyncTable.SyncDirection = SyncDirection.DownloadOnly;**

         this.Configuration.SyncTables.Add(customerSyncTable);
         this.Configuration.SyncParameters.Add(new SyncParameter("@CustomerName", "Sharp Bikes"));
     }

} 

      

+3


source


There are several new database-related sync providers in Sync Framework 2.0 - they have a number of advantages over those previously available (see Comparison of Provider Types here ). With these, you can specify that a subset of tables should be synchronized by creating a DbSyncScopeDescription containing DbSyncTableDescriptions only for the tables you want to synchronize.



You stated above that you are not interested in filtering data, but it is probably worth mentioning here that DbSyncScopeDescription also contains filtering information.

+2


source







All Articles