将 LINQ-to-SQL DBML 架构与 SQL Server 数据库同步

发布于 2024-09-02 17:54:24 字数 248 浏览 0 评论 0原文

创建 SQL Server 2008 数据库后,我在 Visual Studio 中创建了 Linq-to-SQL 架构。接下来,在 .dbml 可视化编辑器(在 Visual Studio 2010 中)中,我将 PK-to-FK 和 PK-to-PK 关联添加到架构中。

如何将我在 Visual Studio 中创建的关联复制到数据库?换句话说,我如何与数据库同步

After creating a SQL Server 2008 database, I made a Linq-to-SQL schema in Visual Studio. Next, in the .dbml visual editor (in Visual Studio 2010), I added PK-to-FK and PK-to-PK associations to the schema.

How do I copy those associations that I created in Visual Studio over to the database? In other words, how do I sync with the DB?

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

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

发布评论

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

评论(1

旧时浪漫 2024-09-09 17:54:24

Linq-to-SQL 是一个很棒的工具,但永远不要依赖它来更新架构。始终通过升级 SQL 脚本应用架构更改,这些脚本使用 DDL CREATE/ALTER/DROP 语句从 磁盘版本到当前版本。通过这种方式,您可以将所有架构更改作为源文本文件保存在版本控制下,您可以从任何过去的版本升级到当前的应用程序版本,并且可以轻松测试所有升级路径,包括升级具有非常大的表的部署。

更糟糕的选择是使用 SQL 比较工具,它可以将您所需的架构与部署的架构进行区分,例如 vsdbcmd。这可能适用于琐碎的部署,但复制和重命名包含数百万条记录的表将很快显示出它的丑陋的缺点。

您绝对不能依赖 .dbml 文件作为模式的“主”副本。这是 Linq-to-SQL 倡导者通常会忽略的一个小细节,当您尝试交付应用程序的 v2 并意识到您没有升级工具集时,您通常会发现这一点。

Linq-to-SQL is a great tool, but never ever rely on it to update the schema. Always apply schema changes through upgrade SQL scripts that use DDL CREATE/ALTER/DROP statements to change the deployed schema from the on-disk version to the current version. This way you keep all you schema changes under version control as source text files, you can upgrade from any past version to the current application version and you can easily test all your upgrade paths, including upgrading deployments with very large tables.

The far worse alternative is to use SQL compare tools that can diff your desired schema from your deployed schema, like vsdbcmd. This may work on trivial deployments, but copying and renaming tables of millions of records will quickly show it's ugly downside.

What you absolutely cannot do is rely on the .dbml file as the 'master' copy of your schema. This is a little detail usually omitted by the Linq-to-SQL advocates, one that you discover usually when you attempt to deliver v2 of your application and realize you have no upgrade tool set.

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