同步框架:我可以仅同步表的子集吗?

发布于 2024-07-10 12:21:37 字数 265 浏览 4 评论 0原文

使用同步框架同步数据的常规代码片段是这样的:

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

有谁知道同步我的表子集的方法吗? 不要注意每个表内的数据,而是决定哪些表将参与同步。

谢谢 爱丽儿

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春庭雪 2024-07-17 12:21:37

是的,你绝对可以。

为每个要同步的表创建一个 SyncTable,并将其添加到 SyncAgent 中的 Configuration.SyncTables 中。

我发现这篇文章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"));
     }

} 

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

} 
温暖的光 2024-07-17 12:21:37

Sync Framework 2.0 中有一些新的与数据库相关的同步提供程序 - 与以前可用的同步提供程序相比,它们具有许多优点(请参阅比较提供程序类型 此处)。 通过这些,您可以通过构建仅包含您希望同步的那些表的 DbSyncTableDescription 的 DbSyncScopeDescription 来指定应同步表的子集。

您在上面说过您对过滤数据不感兴趣,但这里可能值得一提的是,DbSyncScopeDescription 还包含过滤信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文