Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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.

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

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.

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?

like image 466
Evonet Avatar asked Oct 05 '13 10:10

Evonet


People also ask

How to configure Visual Studio to work with TFS?

1) Launch Visual Studio.NET and set TFS as the default source control repository. Go to Tools => Options => Source Control. Then click OK. 2) Go to View => Team Explorer and connect to TFS server using the icon 3) Create a C# ASP.NET Web project

Should I use Entity Framework or database project migrations?

In this fashion, you can use both techniques, but not have to write two sets of code for your database design. Your DBA can now use migrations from either the Database Project, or the Entity Framework migrations. They have a choice as do you.

How to add a solution to TFS source control?

7) Add the solution to TFS source control. Right click on the solution and select ‘ Add solution to Source Control’ 8) Select the Team Project created earlier and then click OK 9) The solution is not yet checked-in to the TFS. In the Team Explorer click on the source control explorer and you can see the solution added to be checked in.

How to use Microsoft TFS 2015 update 3?

Using Microsoft TFS 2015 Update-3 for.NET (Build, Test and Deploy): TFS Tutorial TFS is more widely used for.NET development using Visual Studio.NET IDE. With TFS 2015 Update 3, one can connect to any Team Foundation Server Git repo, using an SSH key.


1 Answers

Entity Framework Code First is 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.

SQL Server Database projects are 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.


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).

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

Note:

You should consider installing the SQL Server Data Tools as 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

like image 190
jessehouwing Avatar answered Oct 10 '22 18:10

jessehouwing