What is the advantage of CodeFirst over the database?

I watched several videos and tutorials for EF 4.1, and I do not understand any of the benefits of CodeFirst (except for some if DB are very small 3-4 tables, and I'm lazy to create a database).

In most cases, the best approach so far is to create a database in some kind of database editor, which is undoubtedly faster than editing in the Entity model, and EF selects all relationships and creates associations correctly. I know that there are problems in the naming convention, etc., but I feel that it is very confusing to manage Code First, since everything looks like code and there is too much for coding.

What can CodeFirst do, but Db can't at first?

+8
ef-database-first ef-code-first
source share
4 answers

CodeFirst cannot do what the database cannot at first. At the end of the day, they both use the Entity Framework.

The main benefits of using codefirst are:

  • Development speed . You do not need to worry about creating a database that you are just starting to code. Good for developers coming from programming without much experience with DBA. It also has automatic database updates, so whenever you model changes, the database is also automatically updated.
  • POCOs - the code is much cleaner, you do not get downloads of automatically generated code. You have full control over each of your classes.
  • Simple - you do not have an edmx model to upgrade or support

For more information, see Code-first vs Model / Database-first and here is Code-First or Database-First, how to choose?

+17
source share

Based on the DataCentric approach, it will always be strange to me that people like to create in Code First Approach. When I create my database, I already think about the fact that each of the tables is the same as if they were classes. How they are combined and how the data will be transmitted. I can represent the whole system through a database.

I've always been taught that you work from scratch, get your basics right, and everything else will follow. I create many and many different systems for many different companies, and the speed I do is based on the fact that as soon as I have a strong database model, I start my own code generator that creates Views / stored procedures as also my controller / BusinessLayer / DataLayer for me. Put it all together, and all I need to do is create an interface.

If I had to first create the entire system in code to generate the database, as well as all the other elements, then I would like it to take a lot more time. I am not saying that I am right in any terms, and I am sure that there are probably faster and more experienced ways to develop systems, but so far I have not found them.

Thank you for letting me talk, and I hope that my views have helped a bit.

+7
source share

Migration was included in EntityFramework 4.3 for CodeFirst, so you can easily update changes from model to database Link 1

detailed video: Full reference video

+2
source share

Well, it depends on your project. I will try to make synthase some ideas:

  • You have full control over entity classes. They are no longer generated, you do not need to update T4 templates or use partial classes ...
  • The EDMX model will disappear in EF7 in favor of the CodeFirst model. Therefore, keep in mind if you plan to upgrade to EF or you have projects in the near future that can use EF7.
  • It’s easier to merge if several developers are working on the +/- model. Annotations and matching must be done manually. I would say that the first approach of the code seems easier (less sophisticated), and we can keep things simple (the visual model can hide undesirable complexity). Open API
  • You can still visualize the model using Power Tools, but the model is read-only. Any change to the model must be done manually (even the original objects can be generated from scratch). You do not have partial models (diagrams), but our models should be small enough.
  • It seems that the database is first better integrated with SP and feature results (some improvements were made in EF6)
+1
source share

All Articles