Sync Framework : Can I Sync only a subset of my tables?

久未见 提交于 2019-12-01 10:52:45

问题


The regular code snippet of syncing data with sync framework is this:

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

Do anynody knows a way to sync a subset of my tables. Note not the data inside each table but the decide which tables would be involved in the synchronization.

Thanks Ariel


回答1:


Yes, you absolutely can.

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

I found this article from Bill Ryan very instructive. He goes into how to filter data within each table, but there is stuff in there that does 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"));
     }

} 



回答2:


There are some new database related sync providers in Sync Framework 2.0 - they have a number of benefits over the ones that were previously available (see Comparing Provider Types here). With these, you can specify that a subset of tables should be synchronized by building a DbSyncScopeDescription that contains DbSyncTableDescriptions for only those tables that you wish to synchronize.

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



来源:https://stackoverflow.com/questions/385796/sync-framework-can-i-sync-only-a-subset-of-my-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!