What to select between these 2 approaches?
On what parameters we should take this decision?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 22, 2015, 1:45 AM EST
It depends on your requirement if you want full control through c# code then use code first approach otherwise DB first.
Prashant ShindeRank #1,645 · 934 reputationPosted Jan 22, 2015, 1:52 AM EST
Prashant ShindeRank #1,645 · 934 reputationPosted Jan 22, 2015, 1:54 AM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 22, 2015, 1:55 AM EST
If you are new in EF then I will recommend DB first approach. It will easy and simple to use without much configuration. Anyone start to learn FE they should go with EF after having clear idea about that you can go with code first approach so it will be easier.
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 22, 2015, 1:57 AM EST
If your database is ready then go to DB first approach it will create all the classes automatically
Prashant ShindeRank #1,645 · 934 reputationPosted Jan 22, 2015, 1:58 AM EST
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 22, 2015, 2:01 AM EST
Both are good it depends on your requirement only. No one can say one is good other is not.
I think the differences are:
Code first
Database first
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 22, 2015, 2:03 AM EST
CodeFirst cannot do anything that DB first cannot. At the end of the day they are both using the Entity Framework.
The main advantages of using codefirst are:
For more info see Code-first vs Model/Database-first and here Code-First or Database-First, how to choose?
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Jan 22, 2015, 2:04 AM EST
Code-first Vs Database-first
You are a database guy so the best approach for you is an incremental database-first approach where you define the stuff in DB (or VS Database tools) and update your model from the database. This will give you a big control over your database and allow you building the application and the DB incrementally. Why I think you will like it:- You did SQL DB Admin before - you probably know something about DB and how to design them for a performance - EF will not do anything from this for you. EF will not create indexes for you etc.
- 30-40 tables means that you will not build the model in one shoot. You will start with the small model and continuously grow it. Once you start making changes in DB or adding initialization data you will not want to lose these changes and the data. Code-first allows only deleting the whole database and recreating it from scratch. Model-first allow building the DB incrementally but you need Entity Designer Database Generation Power pack and VS 2010 Premium or Ultimate ($5.000-$10.000).
More about differences between DB first, Model first and Code first. Another answer describes differences between code-first and working with designer.Prashant ShindeRank #1,645 · 934 reputationPosted Jan 22, 2015, 3:07 AM EST