5

This question is asked many times, and I always prefer code-first as I like to keep the logic in code.

But now I have a challenge to load screen under 5 seconds and very little time to do things. I have large set of records, and I'm possibly going to retrieve them asynchronously. There are a few doubts in my mind.

  • Does using db-first approach have any benefits in performance over code-first?
  • Should I write the logic in stored procedures or in code (Linq)?
  • Which has less latency: Linq or stored procedures?
1

2 Answers 2

2

I'm pretty sure there isn't any impact in dbfirst or code first performance, because when using db first you create your model with edmx, and when using code first you define your own model, think of it as:

database => model(database first)

model => database(code first)

If you don't want to keep your logic in code then the right way is to use stored procedure, but if you want to keep logic in your code then don't use stored procedure with linq.

linq is always slower, because well query is created on runtime

2
  • so should i use database first if i am going to use stored procedures
    – A.T.
    Dec 18, 2013 at 6:33
  • 2
    if you don't have existing database then I recommend code first entityframework.codeplex.com/…
    – kirie
    Dec 18, 2013 at 6:39
-3

Database vendors have spent hundreds of man years developing and optimizing their systems for performance and efficiency. Its a no-brainer that performance will always be better using native DB models with stored procedures over coding in the app. its almost ludicrous to only use the db as only a container. In addition, stored procedures are compiled and thus quicker, with inline sql in the application the sql will always be compiled by the db before its run, making it less efficient. MVC is more for coders ease rather than for performance driven solutions.

1
  • "Its a no-brainer" - no, its a popular myth, which is as wrong as the opposite that it is always "better" to implement as much in the app as possible. The truth is: the best performance is achieved by balancing things between server and client.
    – Doc Brown
    Jun 9, 2017 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.