Possible Duplicate:
EF 4.1 Code-first vs Model/Database-first
I just start learning about EF 4.0 CodeFirst, I want to hear from experts about What are the EF CodeFirst advantages and disadvantages ?
Possible Duplicate:
EF 4.1 Code-first vs Model/Database-first
I just start learning about EF 4.0 CodeFirst, I want to hear from experts about What are the EF CodeFirst advantages and disadvantages ?
I think each approach is more suited to different scenarios:
Scenarios in which Database-first or Model-First are recommended:
Scenarios in which Code-first is recommended:
If you want a long lasting database which is dynamic enough to contain ever-changing structure, then consider generic classes/tables that your model/schema reuses for varying/context-dependant purposes.
Update:
I now recommend using Code-First for additional cases:
I've always been an advocate for Data Centric approach, and I believe this is where the advantages and disadvantages come from.
If your strengths are in Database Design and Development, you may find it easier and more intuitive to develop from a database schema. However, if you think better in objects and classes, or if you are working directly from a class model you may be better off starting from a CodeFirst perspective.
Personally, I find myself having to make more changes working from a CodeFirst standpoint that from a "DataFirst" generating my classes.
The main difference is that Code First requires that you define everything in code, whereas Model/Database first require you to define everything in XML/Designer, and only define minimal things in code.
For example, if you want two way navigation properties, then you have to write the code for that in each of your entities. This is generated automatically for you when using the other methods.
I like the power Code first gives you, but most of the time i just can't be bothered to do all that.
For the most part, you get exactly the same thing. It's just how you model it.
The other disadvantage is that (currently) in Code first, when you make changes, it drops the table and recreates it. Losing all data (you can of course seed the database, but you won't get back data you might have entered manually). This will be solved when the Code First Migrations product is released.