0

We are re-writing our web applications( at least 3) and unifying our databases into one. Now the question is do we go Code first or Database first. We will be using MVC 5 and SQL 2014. Any Pros and Cons other than just the preference would be high appreciated

Thank you

Nimmi
  • 1

2 Answers2

1

Code-First gives you the opportunity to develop rich domain model which is not entirely affected by the database and EF. That is the principal benefit of starting with code.

It is generally possible to fit the model into existing database. That asks for a bit of imagination and compromises here and there.

Database-First approach tends to make too many compromises that are ruining the domain model. This often leads to so-called anemic domain model, where most of the domain logic gets pushed into controllers. This in turn significantly reduces use of objects in the solution, leading to lack of flexibility and to tight coupling.

Bottom line is that in my projects I prefer Code-First. This is because I am an object-oriented programmer and that gives me the opportunity to develop proper object-oriented application.

Zoran Horvat
  • 9,447
  • 3
  • 26
  • 39
  • Thanks Zoran, totally agree if we had one application. We will be having 3 applications using the same database. In that case wouldnt it become complicated to go for code first ? There would also be a dependency to deploy all applications – Nimmi Sep 29 '16 at 12:35
  • The problem with Code First is its inability to represent and utilise the many strong data constraints and integrity checks available in most RDBMS systems. It also ties your entire stack to your business layer. What if you want another application (e.g. in Java) to work with the database? – Dai Sep 29 '16 at 12:37
  • @Nimmi I think that EF today is mature enough to cope with that. I still vote for code first because it gives huge advantage when it comes to designing domain model. – Zoran Horvat Sep 29 '16 at 18:39
  • @Dai Relying on RDBMS is largely deprecated today because large applications are coming with dynamic consistency rules, which cannot be modeled in database. DDD, for example, advocates rich domain model, with polymorphic rules that are governing data consistency. – Zoran Horvat Sep 29 '16 at 18:43
1

If you are rewriting your software i think the specifications are almost clear. In this scenario I usually prefer the db-first approach if you have familiarity with ER modelling. (I'm used to do code-first for local database, but db first for server apps/apis)

Code first is very flexible for developing process, especially when model changes often. But if you have a clear analysis of your requrements and familiarity with ER modelling then you can design a good model and decouple developing steps.

Grappachu
  • 711
  • 7
  • 14