2

I have searched a lot, and it also defies my common sense, but is there any possible way that the following statement is true?

Use of Database first is better "performing" than code first?

Erik Philips
  • 48,663
  • 7
  • 112
  • 142
Trainee4Life
  • 2,124
  • 1
  • 19
  • 38
  • 1
    I updated your question because, database first creates [poco's](http://en.wikipedia.org/wiki/Plain_Old_CLR_Object) using T4 templates. Poco really has nothing to do with Code First vs Database First. – Erik Philips Feb 15 '14 at 12:33
  • You can read below answer for more details : http://stackoverflow.com/questions/5446316/code-first-vs-model-database-first?rq=1 – MRG Feb 15 '14 at 12:36

2 Answers2

2

Is this a true statement:

Use of Database first is better "performing" than code first?


First, let's define, what does "better performing" mean, exactly?

Generally speaking, when we think of performance, we think of the speed and/or efficiency of executing code at runtime.

  • There is absolutely no difference to an already running application as to whether the database was created and then code (ORM entities, etc.) was generated afterwards, or vice versa, because when the application is running, all of that process has already taken place at compile-time.

  • Any process that takes place at compile time has no bearing on the runtime performance of an application.

  • There may be a caveat that compile-time is important, particularly with large projects that have a complicated build process; in these cases, taking into account practices that may impact the needed time for building projects may be a valid consideration; however, this does not apply to the performance of the application when it is running.

Therefore, the answer to your question is, it is not a true statement, because it makes no difference to the performance of a running application.


Now, there may be debate regarding which methodology is better, more convenient, more scalable, more easily maintainable, easier to work with, easier to optimize (consider also possible future optimizations in your C# code as well as in the SQL database itself).

This debate will likely have great arguments on both sides. However, such a debate isn't suitable to the Q&A format of StackOverflow and as such I'll avoid sticking my opinion in here as to which method I prefer.


All I can say is do your research regarding the pros and cons of both approaches, and choose the approach that best fits you and/or your team's business needs.

Dmitriy Khaykin
  • 5,088
  • 1
  • 18
  • 31
  • Yes, I was specifically concerned about run-time performance. I thought about mentioning that, but for some reason skipped. – Trainee4Life Feb 16 '14 at 07:14
1

I don't suppose there is any performance difference between those 2. Simply you have to choose one over another due to below mentioned scenarios.

Code first

  • You have Full control over the code.There is no auto generated code.
  • EF will handle DB creation and you don't want to know how it happens.

Database first

  • It's good, If you have existing DB.

This simple decision tree will read everything, in short.

enter image description here

Sampath
  • 50,641
  • 40
  • 250
  • 357