使用 Microsoft Sync Framework 自动创建客户端架构

发布于 2024-08-23 07:57:44 字数 721 浏览 6 评论 0原文

我需要在 .NET 应用程序中制作数据库的本地副本,以便它可以离线运行。我的服务器数据库是 SQL Server 2005,它正在复制到 SQL Server 2008 Express。

它不必是任何花哨的东西 - 只需从头开始(或删除现有数据库),复制所有表/约束/外键,并从某些表复制数据。我不介意在数据库中保留“架构版本”,以便应用程序知道其现有架构何时已过时。

我一直在研究 Microsoft Sync Framework,看来我必须为数据库中的每个表创建一个 SyncTable,坦率地说,这似乎需要太多工作和维护。这是我在示例中找到的代码:

SyncTable orderDetailSyncTable = new SyncTable("OrderDetail");
orderDetailSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
orderDetailSyncTable.SyncDirection = SyncDirection.Snapshot;
orderDetailSyncTable.SyncGroup = orderSyncGroup;
this.Configuration.SyncTables.Add(orderDetailSyncTable);

我想我可以列出数据库中的所有表并枚举它们,但似乎应该有更好的方法。我是否在同步框架中遗漏了某些内容,或者是否有其他内容可以完成此类事情?

I need to make a local copy of a database in a .NET app so that it can function offline. My server database is SQL Server 2005, and it's copying to SQL Server 2008 Express.

It doesn't have to be anything fancy - just start from scratch (or delete the existing db), copy all tables/constraints/foreign keys, and copy data from some of the tables. I don't mind keeping a "schema version" in my database so that the app knows when its existing schema is outdated.

I've been looking into the Microsoft Sync Framework, and it appears that I have to make a SyncTable for each table in my database, and frankly, that seems like too much work and maintenance. This is the code that I'm finding in examples:

SyncTable orderDetailSyncTable = new SyncTable("OrderDetail");
orderDetailSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
orderDetailSyncTable.SyncDirection = SyncDirection.Snapshot;
orderDetailSyncTable.SyncGroup = orderSyncGroup;
this.Configuration.SyncTables.Add(orderDetailSyncTable);

I suppose I could list all the tables in my database and enumerate over them, but it just seems like there should be a better way. Am I missing something in the Sync Framework, or is there something else that would accomplish this sort of thing?

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

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

发布评论

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

评论(1

将军与妓 2024-08-30 07:57:44

我放弃了Sync Framework;使用 SQL Server 管理对象来完成此操作。

http://msdn.microsoft.com/en-us/library/ms162169。 ASPX

I gave up on Sync Framework; using SQL Server Management Objects to accomplish this instead.

http://msdn.microsoft.com/en-us/library/ms162169.aspx

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