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

后端 未结 2 955
刺人心
刺人心 2021-01-16 03:33

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

LocalDBSyncAgent syncAgent = new LocalDBSyncAgent();
Microsoft.Synchronization.Data.Syn         


        
2条回答
  •  孤街浪徒
    2021-01-16 04:12

    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(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"));
         }
    
    } 
    

提交回复
热议问题