Question

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?
Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
scroll top