git Visual Studio 2013 数据库项目如何与 TFS 联机和 EntityFramework 代码首次迁移一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19196994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:09:09  来源:igfitidea点击:

How do Visual Studio 2013 Database Projects work with TFS online and EntityFramework code first migrations

sql-servergitvisual-studioentity-frameworktfs

提问by Evonet

Fairly long title, but hopefully self-explanatory!

标题相当长,但希望不言自明!

I'm starting a new project in Visual Studio 2013 using Entity Framework 5.0 with code first migrations.

我正在使用 Entity Framework 5.0 和代码优先迁移在 Visual Studio 2013 中启动一个新项目。

I've connected my project to TFS Online using git - I'm interested in trying TFS Online as it offers source control management for 5 free projects (similar to BitBucket) but with strong Visual Studio integration.

我已经使用 git 将我的项目连接到 TFS Online - 我有兴趣尝试 TFS Online,因为它为 5 个免费项目(类似于 BitBucket)提供源代码控制管理,但具有强大的 Visual Studio 集成。

I've not used Database projects in Visual Studio 2013 and I've found little information for how this all fits together.

我没有在 Visual Studio 2013 中使用过数据库项目,而且我几乎没有找到关于这一切如何组合在一起的信息。

What I'm trying to acheive is to create a simple Visual Studio solution with 2 projects - one an MVC .NET project and the other a database project. My goal is that code first migrations will make the neccessary changes to the sql scripts in the database project (which are managed under git source control). My web.config points to a local .mdb file as my database which is what is updated when I run update-database in EF which is what I feel is the problem.

我想要实现的是创建一个简单的 Visual Studio 解决方案,其中包含 2 个项目 - 一个是 MVC .NET 项目,另一个是数据库项目。我的目标是代码优先迁移将对数据库项目(在 git 源代码控制下管理)中的 sql 脚本进行必要的更改。我的 web.config 指向一个本地 .mdb 文件作为我的数据库,这是我在 EF 中运行 update-database 时更新的内容,我觉得这是问题所在。

How can I point EF to use my database project for code migration, and subsequently how can I automatically build my development database into a local .mdb file when debugging my solution?

如何让 EF 使用我的数据库项目进行代码迁移,以及如何在调试我的解决方案时自动将我的开发数据库构建到本地 .mdb 文件中?

回答by jessehouwing

Entity Framework Code Firstis a way to manage your SQL Schema. The single source of the truth lives in your code base. Migrations adds a way to move from one version of the schema to another. The SQL schema is a by-product of the build process.

Entity Framework Code First是一种管理 SQL 架构的方法。真相的唯一来源存在于您的代码库中。迁移添加了一种从模式的一个版本移动到另一个版本的方法。SQL 模式是构建过程的副产品。

SQL Server Database projectsare also a way to manage your SQL Schema. The single source of the truth lives in your SQL Server Database project. You can use schema compare to generate scripts that move from one version to another.

SQL Server 数据库项目也是管理 SQL 架构的一种方式。事实的唯一来源存在于您的 SQL Server 数据库项目中。您可以使用模式比较来生成从一个版本移动到另一个版本的脚本。



Given that these technologies overlap in their intent and functionality, it doesn't really make sense to use them together. When you're using entity Framework Code First, leverage Migrations when you can (and when the features are sufficient for your situation).

鉴于这些技术的意图和功能重叠,将它们一起使用实际上没有意义。当您使用实体框架 Code First 时,请在可能的情况下(以及当功能足以满足您的情况时)利用迁移。

When you're unable to use Migrations, you could use SQL Server Database projects to manage the schema and keep them in source control.

当您无法使用迁移时,您可以使用 SQL Server 数据库项目来管理架构并将它们保留在源代码控制中。

Note:

注意

You should consider installing the SQL Server Data Toolsas a replacement for the SQL Server Database projects should you want to use these. The data tools are a more advanced version of these projects, even if they might require Visual Studio 2012 to run for now. I suspect a version for Visual Studio 2013 will be available when Visual Studio 2013 hits RTM

如果要使用 SQL Server 数据库项目,您应该考虑安装SQL Server Data Tools作为 SQL Server 数据库项目的替代品。数据工具是这些项目的更高级版本,即使它们现在可能需要 Visual Studio 2012 才能运行。我怀疑当 Visual Studio 2013 达到 RTM 时,Visual Studio 2013 的版本将可用