11

I have been given a spec to create a new MVC4 website, it will not be too large a project at first but I suspect it will grow as the business gets new ideas for it.

Using .NET 4.5 ASP.NET MVC4 and EF I have to choose between code-first with migrations or Sql Server Data Tools (SSDT) for handling my database.

With the SSDT I can control my database in a project as part of my solution and handle the changes all the way from dev through to production and beyond using dacpac files. My experience of code-first from MVC3 was not to use it beyond development due to the limited database options. It would always end up with dropping the Db on model change or handle the Db changes manually. However I am led to believe with MVC4 Migrations that is no longer the case and I can now push updates to the Db.

So my question is which one is the most efficient to use based on saving time/effort in development but also scalable and able to handle production changes. I liked code-first and the ability to generate my Database from Models, does the introduction of migrations now make it viable in production?

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
Lotok
  • 1,759
  • 2
  • 17
  • 27

1 Answers1

2

My personal opinion is that codefirst great tool and great for development. The steps of databasefirst development should be scripting external tools or by hand, if you already have a production database.

The codefirst to be included in the development of database version control system and provides a distributed database development.

Starting point, it's a good series:

http://coding.abel.nu/2012/02/using-entity-framework-to-create-a-database/

Gábor Plesz
  • 136
  • 3
  • Have you tried the ssdt, able to compare the 2? – Lotok Jun 05 '13 at 16:05
  • 1
    Yes, I use it regularly in previous version of SSDT. I looked the newest at these links: http://msdn.microsoft.com/en-us/jj650015, http://sqlblog.com/blogs/jamie_thomson/archive/2013/03/21/considerations-when-starting-a-new-ssdt-database-project.aspx, http://www.develop.com/sqlservertwelvedatatools, http://blogs.msdn.com/b/ssdt/archive/2012/12/13/available-today-ssdt-december-2012.aspx. I have not tried the database unit test, but I think the key is to be used next to each other the codefirst *and* the SSDT. – Gábor Plesz Jun 06 '13 at 08:30
  • I will read those blogs soon. I didn't think code-first and SSDT would work side by side. Unless you mean using code-first during dev and switching to SSDT for production? I will read your links! – Lotok Jun 06 '13 at 09:12
  • I'm doing database development code first method. The codefirst migration solves the steps to install the database (creating a new table, a new column to an existing table, etc). For example, if you want to create database *unit tests*, you can also use the SSDT. If we want to *compare two structures*, also can use the SSDT. At least, so I use it. Development and deployment of codefirst very good. – Gábor Plesz Jun 06 '13 at 11:01
  • From what I seem SSDT is perfect for Db First and from everything you said and posted it seems the migrations options added to MVC4 do in fact make code-first usable beyond initial dev! – Lotok Jun 06 '13 at 11:20
  • When driving at any time be changed to code first development. You can check this: http://stackoverflow.com/questions/15268036/edmx-for-legacy-code-and-code-first-for-new-development-together-in-one-mvc-pr (Edit II: From DB First to CodeFirst, we choose the following...) The transition is about 10 minutes if entity framework that has been used. I can tell you that the greatest development, which is now used codefirst half years ago, contains 80 database tables, and the development of the database are not insurmountable problems. – Gábor Plesz Jun 06 '13 at 13:26
  • Some good reading. I loved code-first when I first tried it and was disappointed by its short-comings in production. Looks like it has become viable. woo! :) – Lotok Jun 07 '13 at 07:03
  • I'm glad you like it. I'm a big fan of codefirst, and I'd appreciate it if i hear about your experiences. – Gábor Plesz Jun 07 '13 at 08:39