简体   繁体   English

同步框架:我可以仅同步部分表吗?

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

The regular code snippet of syncing data with sync framework is this: 使用sync框架同步数据的常规代码段是这样的:

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

Do anynody knows a way to sync a subset of my tables. Do nonody知道一种同步表子集的方法。 Note not the data inside each table but the decide which tables would be involved in the synchronization. 注意不是每个表中的数据,而是决定同步中将涉及哪些表。

Thanks Ariel 谢谢爱丽儿

Yes, you absolutely can. 是的,您绝对可以。

Create a SyncTable for each table you want to sync, and add it to the Configuration.SyncTables in the SyncAgent. 为每个要同步的表创建一个SyncTable,并将其添加到SyncAgent中的Configuration.SyncTables。

I found this article from Bill Ryan very instructive. 我发现Bill Ryan的这篇文章很有启发性。 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: 来自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"));
     }

} 

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 ). Sync Framework 2.0中有一些新的与数据库相关的同步提供程序-与以前可用的同步提供程序相比,它们具有许多优点(请参阅此处的比较提供程序类型)。 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. 使用这些,您可以通过构建一个DbSyncScopeDescription来指定应同步表的子集,该DbSyncScopeDescription仅包含要同步的表的DbSyncTableDescriptions。

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. 上面您说过,您对过滤数据不感兴趣,但是在这里值得一提的是DbSyncScopeDescription也包含过滤信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM