what is the difference between data first approach and code first approach.
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Oct 26, 2016, 10:32 AM EDT
+1
Hi,
I think the differences are:This is best answer .
Code first
Very popular because hardcore programmers don't like any kind of designers and defining mapping in EDMX xml is too complex.
Full control over the code (no autogenerated code which is hard to modify).
General expectation is that you do not bother with DB. DB is just a storage with no logic. EF will handle creation and you don't want to know how it does the job.
Manual changes to database will be most probably lost because your code defines the database.
Database first
Very popular if you have DB designed by DBAs, developed separately or if you have existing DB.
You will let EF create entities for you and after modification of mapping you will generate POCO entities.
If you want additional features in POCO entities you must either T4 modify template or use partial classes.
Manual changes to the database are possible because the database defines your domain model. You can always update model from database (this feature works quite good).
I often use this together VS Database projects (only Premium and Ultimate version).
I expect that in case of EF 4.1 there are several other features related to Code First vs. Model/Database first. Fluent API used in Code first doesn't offer all features of EDMX. I expect that features like stored procedures mapping, query views, defining views etc. works when using Model/Database first and DbContext (I didn't try it yet) but they don't in Code first.
+1
Rajeesh MenothRank #118 · 18.4K reputationPosted Oct 26, 2016, 3:33 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Oct 26, 2016, 10:32 AM EDT
Code first
Database first
I expect that in case of EF 4.1 there are several other features related to Code First vs. Model/Database first. Fluent API used in Code first doesn't offer all features of EDMX. I expect that features like stored procedures mapping, query views, defining views etc. works when using Model/Database first and
DbContext(I didn't try it yet) but they don't in Code first.Rajeesh MenothRank #118 · 18.4K reputationPosted Oct 26, 2016, 3:33 AM EDT
Ravi PatelRank #439 · 5.7K reputationPosted Oct 26, 2016, 5:23 AM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Oct 26, 2016, 6:29 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts